Open staticdev opened 2 years ago
Hey @staticdev,
by default Poetry will use the interpreter it was installed with to create a new venv. If it should instead take whatever is the activated Python in your current shell set virtualenvs.prefer-active-python
to true
.
fin swimmer
@finswimmer thanks a lot for the prompt response and clarification! It was very helpful =)
I did poetry config virtualenvs.prefer-active-python true
and recreated the environment, everything worked. Still I think the behavior is not totally consistent with what you said. When I had poetry config virtualenvs.prefer-active-python false
, I used poetry install, it was using python 3.9.2 (probably the version I installed it), but the folder created was named with py3.10
. And also I find strange to say:
The currently activated Python version 3.9.2 is not supported by the project (>=3.10.0,<4.0).
Trying to find and use a compatible version.
Using python3 (3.10.6)
This two points made me confused, even using poetry for years now. Questions:
py3.9
?python = ">=3.10.0,<4.0"
maybe then I should get an error right away. This would also prevent confusing messages of warning and error after this point.@finswimmer I am having same problem on Mac, but this time poetry config virtualenvs.prefer-active-python true
is not my friend. I always have:
Current Python version ... is not allowed by the project...
Please change python execute via the "use env" command.
poetry use env also does not change the result.
I'm also experiencing a similar issue, which seems to contradict the documentation here: https://python-poetry.org/docs/managing-environments/
By default, Poetry will try to use the Python version used during Poetry’s installation to create the virtual environment for the current project. However, for various reasons, this Python version might not be compatible with the python requirement of the project. In this case, Poetry will try to find one that is and use it. If it’s unable to do so then you will be prompted to activate one explicitly, see Switching environments.
While I am using pyenv, I don't think the prefer-active-python setting is relevant here. I don't care if poetry uses the currently active version but I would like it to use a version that meets the project dependencies, and it looks like it is trying to :)
Poetry was installed using python 3.9.13 initially. I have 3.9.13 and 3.10.6 available via pyenv. My current project wants ^3.10
[tool.poetry.dependencies]
python = "^3.10"
poetry should look for python 3.10.x and create the virtual environment using the discovered version, or prompt otherwise. From the output, it appears to find 3.10.6 but when I inspect the created virtual environment afterwards, it is python 3.9.13
$ poetry install
The currently activated Python version 3.9.13 is not supported by the project (^3.10).
Trying to find and use a compatible version.
Using python3 (3.10.6)
Creating virtualenv flask-huey-DOCxGAqz-py3.10 in /home/dmartins/.cache/pypoetry/virtualenvs
....
$ poetry env info
Virtualenv
Python: 3.9.13
Implementation: CPython
Path: /home/dmartins/.cache/pypoetry/virtualenvs/flask-huey-DOCxGAqz-py3.10
Executable: /home/dmartins/.cache/pypoetry/virtualenvs/flask-huey-DOCxGAqz-py3.10/bin/python
Valid: True
System
Platform: linux
OS: posix
Python: 3.9.13
Path: /home/dmartins/.pyenv/versions/3.9.13
Executable: /home/dmartins/.pyenv/versions/3.9.13/bin/python3.9
$ cat /home/dmartins/.cache/pypoetry/virtualenvs/flask-huey-DOCxGAqz-py3.10/pyvenv.cfg
home = /home/dmartins/.pyenv/versions/3.9.13/bin
implementation = CPython
version_info = 3.9.13.final.0
virtualenv = 20.16.7
include-system-site-packages = false
base-prefix = /home/dmartins/.pyenv/versions/3.9.13
base-exec-prefix = /home/dmartins/.pyenv/versions/3.9.13
base-executable = /home/dmartins/.pyenv/versions/3.9.13/bin/python3.9
prompt = flask-huey-py3.10
edit: including my current poetry config
cache-dir = "/home/dmartins/.cache/pypoetry"
experimental.new-installer = true
experimental.system-git-client = false
installer.max-workers = null
installer.no-binary = null
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs" # /home/dmartins/.cache/pypoetry/virtualenvs
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{project_name}-py{python_version}"
edit2:
With virtualenvs.prefer-active-python = true
:
With virtualenvs.prefer-active-python = false
:
with 3.9.13 active, poetry looks for a version matching ^3.10 and selects 3.11.0 (Fedora 37 system python) and creates a venv using 3.11.0
with 3.10.6 active, poetry creates a 3.9.13 venv (though output suggests it is going to use 3.10.6)
with 3.11.0 active (system python), poetry creates a 3.11.0 venv.
@staticdev a potential workaround for your initial issue is to run poetry env use before any venv with the -py3.10 suffix exists.
poetry env use ~/.pyenv/versions/3.10.6/bin/python
or poetry env use 3.10
<-- creates the venv with 3.10 python.At a glance, this looks like it might be the same behaviour as python-poetry/poetry#7158
Relevant part:
-vvv
option) and have included the output below.Issue
I have many versions of Python installed with Pyenv, but my settings are:
I have created a virtualenv with
poetry install
and when I dopoetry shell
I get:I don't understand this warning since my venv was created with py3.10, my pyenv only has 3.10 and it says
python3 (3.10.6)
.Then after
poetry shell
I get error with:Successful
env use 3.10.6
and again same error:I also tried deleting the folder
/home/user/.cache/pypoetry/virtualenvs/project-0KWPzb1N-py3.10
and creating again the environment but I get the same warning and errors: