poetry
poetry copied to clipboard
`poetry env info` does not respect `virtualenvs.prefer-active-python = true` setting
-
[x] I am on the latest Poetry version.
-
[x] I have searched the issues of this repo and believe that this is not a duplicate.
-
[x] If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option). -
OS version and name: WSL, Ubuntu 20.04
-
Poetry version: 1.2.0b1
Issue
I'm relying on pyenv
to specify which base Python version Poetry should be using. It was incredibly confusing, coming from an old version of Poetry, to find out that there's now a virtualenvs.prefer-active-python
setting which defaults to false
- so has to be set to true
to use Poetry with pyenv
. While that fixes e.g. poetry install
, poetry env info
still ignores pyenv
even with this setting. To get it to provide information about my actual venv I had to wrap the call with poetry run
(for it to pick up pyenv python correctly), i.e. poetry run poetry env info --path
.
As a side note, this new prefer-active-python
setting defauling to false
is such an incredible gotcha. I would think the vast majority of (linux) users would use Poetry alongside pyenv
(and everyone was using get-poetry.py
installer in the past as it was the recommended one), and this will get them all.
Hello @nirvana-msu,
can you please give an example about the output you see and the one you would expect?
fin swimmer
Try installing poetry from the get-poetry.py
installer.
- Clear poetry installation with
curl -sSL https://install.python-poetry.org | python - --uninstall
rm -rf .cache/pypoetry
- Re-install it with the "deprecated" script
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
and let us know if something changes
@finswimmer I have encountered the same issue, so I can give an example of unexpected behavior.
Setup
My system python is 3.9.11, as is the python poetry
is installed against:
$ poetry debug info
Poetry
Version: 1.2.0
Python: 3.9.11
I take the following pyproject.toml
, trying to use python 3.7 for my project:
[tool.poetry]
name = "example_project"
version = "0.0.1"
description = "Demonstrating an issue."
license = "GNU GPL3"
authors = ["Jacopo Tissino <[email protected]>"]
[tool.poetry.dependencies]
python = ">=3.7,<3.8"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Then (to start, I'll also show the outcome of setting it to true later), I set
$ poetry config virtualenvs.prefer-active-python false
Then, I run
$ pyenv local 3.7.12
$ python --version
Python 3.7.12
Creating the (wrong) virtualenv
Now, (without knowing about the prefer-active-python setting) I'd expect poetry to be using the current python, so that I could run
$ poetry install
The currently activated Python version 3.9.11 is not supported by the project (>=3.7,<3.8).
Trying to find and use a compatible version.
Using python3 (3.7.12)
Creating virtualenv example-project-fEs4NoC1-py3.7 in /home/jacopo/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies... (0.1s)
Writing lock file
while, instead, I see this weird warning: the currently activated python is not 3.9.11!
Incidentally, in the virtualenv's folder I find the unexpected structure:
.../example-project-fEs4NoC1-py3.7/lib/python3.9/site-packages/...
Now, if I try to enter a poetry shell I can spot the problem:
$ poetry shell
The currently activated Python version 3.9.11 is not supported by the project (>=3.7,<3.8).
Trying to find and use a compatible version.
Using python3 (3.7.12)
Spawning shell within /home/jacopo/.cache/pypoetry/virtualenvs/example-project-fEs4NoC1-py3.7
. /home/jacopo/.cache/pypoetry/virtualenvs/example-project-fEs4NoC1-py3.7/bin/activate
$ . /home/jacopo/.cache/pypoetry/virtualenvs/example-project-fEs4NoC1-py3.7/bin/activate
(example-project-py3.7) 18:22:48 jacopo powermetal /home/jacopo/Documents/examples/mwe_poetry
$ python
Python 3.9.11 (main, Jun 10 2022, 15:11:46)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
env info
issues
To relate to the poetry env info
in the question: if I run it following the previous commands (so, with the experimental option off) I get
$ poetry env info
Virtualenv
Python: 3.9.11
Implementation: CPython
Path: NA
Executable: NA
System
Platform: linux
OS: posix
Python: 3.9.11
Path: /home/jacopo/.pyenv/versions/3.9.11
Executable: /home/jacopo/.pyenv/versions/3.9.11/bin/python3.9
Alternatively, I can run
$ poetry run poetry env info
The currently activated Python version 3.9.11 is not supported by the project (>=3.7,<3.8).
Trying to find and use a compatible version.
Using python3 (3.7.12)
Virtualenv
Python: 3.9.11
Implementation: CPython
Path: /home/jacopo/.cache/pypoetry/virtualenvs/example-project-fEs4NoC1-py3.7
Executable: /home/jacopo/.cache/pypoetry/virtualenvs/example-project-fEs4NoC1-py3.7/bin/python
Valid: True
System
Platform: linux
OS: posix
Python: 3.9.11
Path: /home/jacopo/.pyenv/versions/3.9.11
Executable: /home/jacopo/.pyenv/versions/3.9.11/bin/python3.9
which is slightly more informative (why do we need to wrap a poetry command with poetry run, though?).
Experimental option on
If I repeat all the previous procedure with
$ poetry config virtualenvs.prefer-active-python true
I get the correct virtual environment:
$ poetry shell
Spawning shell within /home/jacopo/.cache/pypoetry/virtualenvs/example-project-fEs4NoC1-py3.7
. /home/jacopo/.cache/pypoetry/virtualenvs/example-project-fEs4NoC1-py3.7/bin/activate
$ . /home/jacopo/.cache/pypoetry/virtualenvs/example-project-fEs4NoC1-py3.7/bin/activate
(example-project-py3.7) 18:28:39 jacopo powermetal /home/jacopo/Documents/examples/mwe_poetry
$ python
Python 3.7.12 (default, Mar 22 2022, 16:21:33)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
but indeed, the env info
command gives the wrong results: like before,
$ poetry env info
Virtualenv
Python: 3.9.11
Implementation: CPython
Path: NA
Executable: NA
System
Platform: linux
OS: posix
Python: 3.9.11
Path: /home/jacopo/.pyenv/versions/3.9.11
Executable: /home/jacopo/.pyenv/versions/3.9.11/bin/python3.9
while, as @nirvana-msu noted,
$ poetry run poetry env info
Virtualenv
Python: 3.7.12
Implementation: CPython
Path: /home/jacopo/.cache/pypoetry/virtualenvs/example-project-fEs4NoC1-py3.7
Executable: /home/jacopo/.cache/pypoetry/virtualenvs/example-project-fEs4NoC1-py3.7/bin/python
Valid: True
System
Platform: linux
OS: posix
Python: 3.7.12
Path: /home/jacopo/.pyenv/versions/3.7.12
Executable: /home/jacopo/.pyenv/versions/3.7.12/bin/python3.7
This behavior does feel inconsistent to me, but let me know if I've missed anything! This is all using poetry 1.2.0 + pyenv 2.2.5, on ubuntu 22.04.
Thanks a lot for these information @jacopok :+1: I try to have a look on this in the next week.
I second this, it is not working as expected
I had a similar problem and it seems to come from the file ~/.cache/pypoetry/virtualenvs/envs.toml/
Removing ~/.cache/pypoetry/
solved my issue.
Similarly, I ran into this issue (on mac) & resolved it by removing ~/Library/Application Support/pypoetry
and re-installing.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.