Skip to content

Extension chooses venv from subdirectory when it should not choose any at all #24175

@skirsten

Description

@skirsten

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 the Output panel (ViewOutput, 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"

Installed Extensions
Extension Name Extension Id Version
JavaScript Debugger ms-vscode.js-debug 1.93.0
JavaScript Debugger Companion Extension ms-vscode.js-debug-companion 1.1.3
Pylance ms-python.vscode-pylance 2024.9.2
Python ms-python.python 2024.14.1
Python Debugger ms-python.debugpy 2024.10.0
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.9
System Info
Item Value
CPUs AMD Ryzen 5 9600X 6-Core Processor (12 x 5354)
GPU Status 2d_canvas: enabled
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
Load (avg) 0, 0, 0
Memory (System) 30.49GB (23.78GB free)
Process Argv ***/.vscode/cassie.code-workspace --crash-reporter-id 1b74a203-254e-477f-8e6b-555495738549
Screen Reader no
VM 0%
DESKTOP_SESSION ubuntu
XDG_CURRENT_DESKTOP Unity
XDG_SESSION_DESKTOP ubuntu
XDG_SESSION_TYPE x11
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
vscaat:30438848
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
welcomedialogc:30910334
pythonnoceb:30805159
asynctok:30898717
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
accentitlementst:30995554
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
01bff139:31013167
a69g1124:31058053
dvdeprecation:31068756
dwnewjupytercf:31046870
2f103344:31071589
impr_priority:31102340
nativerepl2:31139839
refactort:31108082
pythonrstrctxt:31112756
flighttreat:31134774
wkspc-onlycs-t:31132770
wkspc-ranged-c:31125598
cf971741:31144450
pme_test_c:31118331
ei213698:31121563
iacca1:31144502
notype1:31143045

Metadata

Metadata

Assignees

Labels

triage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions