-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
pythonTerminalEnvVarActivation shadows pyenv PATH #23227
Comments
hello @kbehlers Thanks for filing the issue. Is this only happening with pyenv?? Is it fine with .venv |
@anthonykim1 Hi! This is only with pyenv, specifically pyenv-virtualenv. Standard pyenv-virtualenv seems to be relying on the existing shim already in the PATH, rather than prepending the venv each time, so the shadowing occurs because the VS Code experiment seems to prepend the venv from the interpreter selected in the Python extension. Exploring the behavior a bit more, if I first |
Hello @kbehlers Thanks much for further looking into this. I think it can be one or either of two problems:
Good to hear that there is at least some workaround if you I'll let you know if I get update on this. |
Related: #21906 Seems to be the PR where we started to use prepend to PATH. With its purpose of attempting to avoid replacing. since pyenv asks their user to manipulate PATH in init script. |
@kbehlers can you share what your PATH looks like? |
@anthonykim1 Sure! Opted out from the experiment
Opted into the experiment
You can see when opted-in it has some interesting prepend and append behavior |
Thanks much for providing PATH. Greatly appreciated! Im not able to repro the behavior on my machine exactly but I do get "pyenv-virtualenv: no virtualenv has been activated." when I try Still lost on why prepending would "not allow" pyenv deactivate to work because your pyenv shim is still technically in your PATH even after Python extension prepend our deactivate script in the PATH. |
@anthonykim1 Ahh, I see so if I am following #21906 and #22905 to it sounds like
might be expected then but I do want to highlight my path is actually ending up as
with the two prepended activated paths and a third appended activated_path. Probably not relevant to the problem, still a little odd to me though. Going back to why prepending would "not allow" pyenv deactivate to work, I've been digging into this a bit more. Built-in venv deactivate manipulates the PATH. pyenv-virtualenv deactivate manipulates some env vars like The way pyenv uses its shims, it expects to do all python routing internally. As with pyenv-virtualenv, pyenv also does not manipulate It was really helpful for me to understand the behavior by repeating my Steps to Reproduce, but checking As I understand it this means by having the venv force prepended to the PATH, Out of the two paths appended
it isn't the Hopefully that is helpful in trying to decide how to adapt the experiment for compatibility with pyenv. |
I'm experiencing a related issue. The appended paths that @kbehlers pointed out are causing problems with conda environments too. Here's what I observed after selecting
As a slight aside, even when opted out, the PATH in VS Code is still a bit different from what I get in a native terminal on my Mac.
Since it's just condabin being reordered, I think it's fine, though a bit odd. |
I might be experiencing problems related to this as well. I'm on osx with pyenv + pyenv virtualenv. pyenv/venv works fine in the OS terminal app. In vscode terminal, everything works fine if I disable vscode terminal integrations. If I source ~/.zshrc or ~/.zprofile in the vscode terminal, pyenv starts working again. The problem I'm seeing is if I open a new terminal with default vscode settings, the wrong pyenv is entered and changing directories does not switch to the correct one. which pip shows the wrong pyenv pip When things are not working, 'which pip' shows: When things are working, 'which pip' shows: |
Correct, this is coming from lack of context in env variables. We are working API microsoft/vscode#227467 so extension has better context of env vars inside .zshrc and other shell init files. |
Closing this against #24567 |
Behaviour
When the pythonTerminalEnvVarActivation experiment is active, I can no longer use pyenv-virtualenv commands for activating and deactivating venvs in the VSCode terminal. Instead the interpreter selected in the Python extension always stays activated in the terminal.
The pyenv-virtualenv commands give the appearance of working (they change my zsh command prompt showing the active venv) but running python commands like
python --version
orpip freeze
show that the python interpreter being used isn't the one shown in my command prompt but instead the one selected using the Python extension in VSCode.It seems possibly related to how pythonTerminalEnvVarActivation prepends to
PATH
.Steps to reproduce:
pyenv install 3.10
pyenv install 3.9
) to make it easier to see when the wrong venv is activefirst_example_env
as the python interpreter in VSCode usingPython: Select Interpreter
echo $PATH
(this shows vscode specific paths when the experiment is enabled)python --version
(should say Python 3.9.*)pyenv deactivate
(doesn't end up deactivating as it should but gives the appearance of doing so by changing the command prompt)pyenv activate second_example_env
(changes the command prompt, doesn't actually change the venv though)python --version
(should say Python 3.10.* but still says Python 3.9.* because the environment didn't really switch)Python: Select Interpreter
and choosesecond_example_env
second_example_env
will be active no matter whatIf I instead add:
to settings.json, I can activate and deactivate venvs using pyenv-virtualenv just as I would expect, where the venv actually switches in the terminal.
Diagnostic data
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)The text was updated successfully, but these errors were encountered: