-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
virtualenvs.prefer-active-python
uses poetry's Python venv, not the active pyenv virtualenv
#8119
Comments
The virtualenvs.prefer-active-python flag is currently not working for me; instead of selecting the local env, I get they poetry venv. This change resolves the problem for me. FIXES: python-poetry#8119
Hey @paultiplady, I'm not sure I can follow you. Maybe you misunderstand what So can you please point out what you've expected to see and what happens instead? This makes it easier to understand whether there is an issue or not. fin swimmer |
Thanks, it looks like I misunderstood what's going on with this flag then. I read #4852 and perhaps didn't read too much into "the pyenv way", assuming that meant how I was familiar with folks using Pyenv. The workflow that I used with Poetry from when it first came out until when it broke some time in the last year was to use pyenv with the pyenv-virtualenv plugin to manage the venv. (The pyenv incantations I shared at the top of my original post). This means when I cd into the project directory, my venv is automatically activated, and I don't need to say In my Dockerfiles I was using It feels like the code that currently exists is pretty close to working as I expect it with To be clear, in the diags I provided above, this command: > poetry env info -vvv
Loading configuration file /Users/paul/Library/Application Support/pypoetry/config.toml
Virtualenv
Python: 3.10.10
Implementation: CPython
Path: NA
Executable: NA
System
Platform: darwin
OS: posix
Python: 3.10.10
Path: /Users/paul/.pyenv/versions/3.10.10
Executable: /Users/paul/.pyenv/versions/3.10.10/bin/python3.10 Is being run inside the venv For what it's worth, I retested this using a non-venv pyenv version and the instructions in https://python-poetry.org/docs/managing-environments/, and that's broken in the same way; I think that is the expected usecase from the docs: ❯ pyenv local 3.9.9
❯ poetry env info
Virtualenv
Python: 3.10.10
Implementation: CPython
Path: NA
Executable: NA
System
Platform: darwin
OS: posix
Python: 3.10.10
Path: /Users/paul/.pyenv/versions/3.10.10
Executable: /Users/paul/.pyenv/versions/3.10.10/bin/python3.10 In this case we should be pulling the My fix resolves this case too (though I see now that we can't hardcode the executable to a |
I also misunderstood how with |
Here's the workaround for any sad soul coming here and seeing no new activity:
|
Seems to work as expected. I also tried to reproduce the output of |
-vvv
option) and have included the output below.Issue
The (experimental)
virtualenvs.prefer-active-python
flag doesn't seem to be working for me.I set up a local pyenv venv with:
pyenv virtualenv 3.10.10 pet pyenv local pet
And this venv is activated automatically in my shell. However Poetry isn't picking it up; if I say
> poetry env info -vvv Loading configuration file /Users/paul/Library/Application Support/pypoetry/config.toml Virtualenv Python: 3.10.10 Implementation: CPython Path: NA Executable: NA System Platform: darwin OS: posix Python: 3.10.10 Path: /Users/paul/.pyenv/versions/3.10.10 Executable: /Users/paul/.pyenv/versions/3.10.10/bin/python3.10
Reading the code, I don't get how this flag is supposed to work; tracing the local code execution we correctly run:
poetry/src/poetry/utils/env/env_manager.py
Lines 237 to 242 in fedff6d
And determine the minor version of the local python to be 3.10. Then we run
poetry/src/poetry/utils/env/env_manager.py
Lines 274 to 275 in fedff6d
And fetch the system python (which is /Users/paul/.pyenv/versions/3.10.10/bin/python3.10 in this case, the pyenv system version that I installed poetry with).
I can't see how this code is supposed to work; it's just extracting
python_minor
from the pyenv interpreter, and maybe looking that up in the poetry virtualenv repo? But of course that won't work for venvs managed by pyenv. It seems to me that EnvManager.get() should just say:Hacking that change in gives me this output:
This seems to be the right interpreter. Does this seem like the right path?
The text was updated successfully, but these errors were encountered: