You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The extension is finding and selecting a venv from a subdirectory for files in the root directory.
This conflicts with the logic described here: https://code.visualstudio.com/docs/python/environments#_where-the-extension-looks-for-environments
It should only search in subfolders in venvPath which is not set by default.
The buggy behaviour is what I would expect if venvPath would be set to the project root.
Basically it will search for a venv in subdirectories as if the venvPath was set to the project directory.
The behaviour is very random and I was shortly able to work around it by providing a non-existing path to venvPath instead of the default empty value. But this solution is not portable and it stopped working for some reason.
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-09-24 22:09:53.440 [info] Experiment 'pythonRecommendTensorboardExt' is active
2024-09-24 22:09:53.440 [info] Experiment 'pythonTerminalEnvVarActivation' is active
2024-09-24 22:09:53.440 [info] Experiment 'pythonTestAdapter' is active
2024-09-24 22:09:53.440 [warning] Dir "/tmp/tmp.xT2EJrx5DO/.pixi/envs" is not watchable (directory does not exist)
2024-09-24 22:09:53.440 [warning] Dir "/tmp/tmp.xT2EJrx5DO/project1/.pixi/envs" is not watchable (directory does not exist)
2024-09-24 22:09:53.440 [warning] Dir "/tmp/tmp.xT2EJrx5DO/project2/.pixi/envs" is not watchable (directory does not exist)
2024-09-24 22:09:53.473 [info] Default formatter is set to ms-python.black-formatter for workspace /tmp/tmp.xT2EJrx5DO
2024-09-24 22:09:53.473 [info] Default formatter is set to ms-python.black-formatter for workspace /tmp/tmp.xT2EJrx5DO/project1
2024-09-24 22:09:53.473 [info] Default formatter is set to ms-python.black-formatter for workspace /tmp/tmp.xT2EJrx5DO/project2
2024-09-24 22:09:53.477 [info] Python interpreter path: ./project1/.venv/bin/python
2024-09-24 22:09:53.513 [info] > pyenv which python
2024-09-24 22:09:53.513 [info] cwd: /tmp/tmp.xT2EJrx5DO
2024-09-24 22:09:53.578 [info] > pixi --version
2024-09-24 22:09:53.578 [warning] could not find a pixi interpreter for the interpreter at /tmp/tmp.xT2EJrx5DO/project1/.venv/bin/python
2024-09-24 22:09:53.692 [info] > . /tmp/tmp.xT2EJrx5DO/project1/.venv/bin/activate && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.14.1-linux-x64/python_files/printEnvVariables.py
2024-09-24 22:09:53.692 [info] shell: bash
2024-09-24 22:09:53.706 [info] > /bin/python3 ~/.vscode/extensions/ms-python.python-2024.14.1-linux-x64/python_files/printEnvVariables.py
2024-09-24 22:09:53.706 [info] shell: bash
2024-09-24 22:09:53.717 [info] Setting environment variable VIRTUAL_ENV in collection to /tmp/tmp.xT2EJrx5DO/project1/.venv {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-09-24 22:09:53.717 [info] Setting environment variable VIRTUAL_ENV_PROMPT in collection to (project1) {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-09-24 22:09:53.717 [info] Prepending environment variable PS1 in collection with (project1) {"applyAtShellIntegration":true,"applyAtProcessCreation":false}
2024-09-24 22:09:53.717 [info] Prepending environment variable PATH in collection with /home/simon/.vscode/extensions/ms-python.python-2024.14.1-linux-x64/python_files/deactivate/bash:/tmp/tmp.xT2EJrx5DO/project1/.venv/bin: {"applyAtShellIntegration":true,"applyAtProcessCreation":true}
2024-09-24 22:09:53.718 [info] Send text to terminal: /bin/python3 /home/simon/.vscode/extensions/ms-python.python-2024.14.1-linux-x64/python_files/printEnvVariablesToFile.py /home/simon/.vscode/extensions/ms-python.python-2024.14.1-linux-x64/python_files/deactivate/bash/envVars.txt
2024-09-24 22:09:54.447 [info] Starting Pylance language server.
As can be seen this time it choose project1. Sometimes it will choose project2 instead...
Extension version: 2024.14.1
VS Code version: Code 1.93.1 (38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40, 2024-09-11T17:20:05.685Z)
OS version: Linux x64 6.8.0-45-generic
Modes:
Python version (& distribution if applicable, e.g. Anaconda): 3.12.3
Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
Value of the python.languageServer setting: Default
User Settings
Multiroot scenario, following user settings may not apply:
languageServer: "Pylance"
@skirsten Are you using the main.code-workspace or opening the folder. When I use the main.code-workspace it seems to work as expected. You should be able to set the python for the root workspace explicitly with select interpreter.
From opening the main.code-workspace that you have I see this:
From the logs:
2024-09-25 13:54:40.893 [info] Send text to terminal: C:/Users/kanadig/AppData/Local/Microsoft/WindowsApps/python3.12.exe c:/GIT/TPI/sep2024/repro-vscode-python-venv-bug/global.py
2024-09-25 13:54:51.575 [info] Send text to terminal: C:/GIT/TPI/sep2024/repro-vscode-python-venv-bug/project1/.venv/Scripts/python.exe c:/GIT/TPI/sep2024/repro-vscode-python-venv-bug/project1/main.py
2024-09-25 13:55:00.469 [info] Send text to terminal: C:/GIT/TPI/sep2024/repro-vscode-python-venv-bug/project2/.venv/Scripts/python.exe c:/GIT/TPI/sep2024/repro-vscode-python-venv-bug/project2/main.py
Type: Bug
Behaviour
The extension is finding and selecting a venv from a subdirectory for files in the root directory.
This conflicts with the logic described here: https://code.visualstudio.com/docs/python/environments#_where-the-extension-looks-for-environments
It should only search in subfolders in
venvPath
which is not set by default.The buggy behaviour is what I would expect if
venvPath
would be set to the project root.Steps to reproduce:
The reproduction is very simple: https://github.com/skirsten/repro-vscode-python-venv-bug
Basically it will search for a venv in subdirectories as if the
venvPath
was set to the project directory.The behaviour is very random and I was shortly able to work around it by providing a non-existing path to
venvPath
instead of the default empty value. But this solution is not portable and it stopped working for some reason.Diagnostic data
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)As can be seen this time it choose project1. Sometimes it will choose project2 instead...
Extension version: 2024.14.1
VS Code version: Code 1.93.1 (38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40, 2024-09-11T17:20:05.685Z)
OS version: Linux x64 6.8.0-45-generic
Modes:
python.languageServer
setting: DefaultUser Settings
Installed Extensions
System Info
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
webnn: disabled_off
A/B Experiments
The text was updated successfully, but these errors were encountered: