-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
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 or pip 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:
- Make sure settings.json has
"python.experiments.optInto": ["pythonTerminalEnvVarActivation"]
- Install pyenv and pyenv-virtualenv
- Install two versions of python with pyenv (e.g.
pyenv install 3.10pyenv install 3.9) to make it easier to see when the wrong venv is active - Create a virtualenv for each version of python
pyenv virtualenv 3.9 first_example_env
pyenv virtualenv 3.10 second_example_env
- Choose
first_example_envas the python interpreter in VSCode usingPython: Select Interpreter - Open a VSCode terminal
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)- Use
Python: Select Interpreterand choosesecond_example_env - Reload the VSCode terminal
- Repeat above steps, except this time
second_example_envwill be active no matter what
If I instead add:
"python.experiments.optOutFrom": ["pythonTerminalEnvVarActivation"]
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 the Output panel (ViewβOutput, change the drop-down the upper-right of the Output panel to Python)
2024-04-11 11:24:39.228 [info] Prepending environment variable PATH in collection with /Users/username/.vscode/extensions/ms-python.python-2024.4.1/python_files/deactivate/zsh:/Users/username/.pyenv/versions/3.9.17/envs/first_example_env/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-04-11 11:24:39.228 [info] Setting environment variable VIRTUAL_ENV in collection to /Users/username/.pyenv/versions/3.9.17/envs/first_example_env {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-04-11 11:24:39.228 [info] Prepending environment variable PS1 in collection with (first_example_env) {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2024-04-11 11:24:39.228 [error] Failed to initialize deactivate script /bin/zsh [Error: "/Users/username/.vscode/extensions/ms-python.python-2024.4.1/python_files/deactivate/zsh/envVars.txt" file not created
at Timeout.<anonymous> (/Users/username/.vscode/extensions/ms-python.python-2024.4.1/out/client/extension.js:2:271175)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)]