koxudaxi / poetry-pycharm-plugin

A PyCharm plugin for poetry

Home Page:https://koxudaxi.github.io/poetry-pycharm-plugin/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to create venv via plugin.

bpleshakov opened this issue · comments

Describe the bug
I am trying to create new venv via poetry and getting this error

Installing dependencies from lock file

PackageInfoError

Unable to determine package info for path: /tmp/pypoetry-git-rembg-forkwsEl10

Fallback egg_info generation failed.

Command ['/tmp/tmp_ogNPR/.venv/bin/python', 'setup.py', 'egg_info'] errored with the following return code 1, and output: 
Traceback (most recent call last):
  File "setup.py", line 1, in <module>
    import pathlib
ImportError: No module named pathlib

/home/sapiosexual/.poetry/lib/poetry/_vendor/py2.7/subprocess32.py:149: RuntimeWarning: The _posixsubprocess module is not being used. Child process reliability may suffer if your program uses threads.
  "program uses threads.", RuntimeWarning)

Python 2.7 will no longer be supported in the next feature release of Poetry (1.2).
You should consider updating your Python version to a supported one.

Note that you will still be able to manage Python 2.7 projects by using the env command.
See https://python-poetry.org/docs/managing-environments/ for more information.

I am perfectly sure I have installed poetry for python3. I am using Python3.8 as base interpreter. I am able to create new venv using terminal.

To Reproduce
Steps to reproduce the behavior:

  1. Go to settings ctrl + alt + s.
  2. Click on Project
  3. Click on Project Interpreter
  4. Click on gear wheel
  5. Click on Add
  6. Click on Poetry Environment
  7. Choose Location and base interpreter
  8. Click on Ok
  9. See error

Expected behavior
Brand new venv with installed dependencies.

Environments (please complete the following information):

  • IDE: PyCharm 2020.3 (Professional Edition)
    Build #PY-203.5981.165, built on December 18, 2020
    Runtime version: 11.0.9+11-b1145.21 amd64
    VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
    Linux 5.4.0-58-generic
  • OS: Ubuntu Ubuntu 20.04.1 LTS
  • Poetry Version 1.1.4
  • Plugin version 1.0.1

@sapiosexual
Thank you for creating this issue.
I guess the poetry was executed by Python2.7.
The latest version of poetry raises an error when running on python2.7.

Would you please try installing poetry with pipx? https://python-poetry.org/docs/#installing-with-pipx
pipx fix python version for each command.

If some users are confused by this behavior of poetry with pyhton2.7, then I implement fallback action on the plugin to execute python3.x.

@koxudaxi
Thank you for your reply.
It seems pipx fixed my issue.
But it is still interesting that usual installation of poetry works fine via cli is executed strictly by python3.8, but plugin runs python2.7 version.
However my issue is closed, have a nice day.

@sapiosexual

It seems pipx fixed my issue.

It's great.

But it is still interesting that usual installation of poetry works fine via cli is executed strictly by python3.8, but plugin runs python2.7 version.

The poetry script is specified the python path in the first line.
This path may be python.
I think the plugin executed the interpreter of the path in your environment.

The python is mapped to python3.8 too.
I actually have zero idea, how poetry script could fall into python2.7.

@abn
Would you please help us?
We have a problem that the PyCharm plugin gets an error when calling poetry.
The reason is the poetry is executed by Python2.7.

This plugin calls poetry from a new process.
I guess this process detects the python execution on line 1 of the poetry file.

$ head -n 1 `which poetry`
#!/usr/bin/env python

A lot of systems will get python2.7 from this shebang.
Unfortunately, Poetry cuts Python2.7, and poetry returns an error when it is executed from Python2.7.

I found a workaround that we use pipx to install poetry.

But, I think a lot of users don't choose this way.
I have two ideas to resolve this problem.

  1. Poetry plugin execute poetry with python3 executable.

  2. Poetry change shebang to python3. #!/usr/bin/env python3

PRO:
We don't touch poetry source code.
CON:
Should we force using Python3? some users may use python2.7 with older poetry.

PRO:
The changes affect only the latest version of users of poetry.
It may help non-pycharm users.

CON:
I don't know how it impacts on source code of poetry.
Windows environment might not the same executable name.

How do you think about this problem?

@koxudaxi but as far as I understand pycharm plugin offers to select base interpreter.
Why just don't use this executable?

Moreover, I think plugin should detect poetry version and show a warning in case user picks python base interpreter that is incompatible with poetry version.

@sapiosexual
I'm sorry for my late reply.

but as far as I understand pycharm plugin offers to select base interpreter.
Why just don't use this executable?

In some cases, the plugin has already detected the base interpreter.
But, It isn't all case. The plugin needs to execute poetry before users select the base interpreter.

Moreover, I think plugin should detect poetry version and show a warning in case user picks python base interpreter that is incompatible with poetry version.

I think this problem is on the poetry side.
We should resolve the problem as possible outside of the plugin.