Skip to content
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

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

Closed
skirsten opened this issue Sep 24, 2024 · 2 comments
Closed
Assignees
Labels
triage-needed Needs assignment to the proper sub-team

Comments

@skirsten
Copy link

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

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Sep 24, 2024
@karthiknadig
Copy link
Member

@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:
image

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

@karthiknadig karthiknadig self-assigned this Sep 25, 2024
@github-actions github-actions bot added the info-needed Issue requires more information from poster label Sep 25, 2024
@skirsten
Copy link
Author

skirsten commented Oct 14, 2024

Hi,

Are you using the main.code-workspace

Yes

When I use the main.code-workspace it seems to work as expected.

I tried it a few more times and its super unpredictable if it will work or not. But it was definitely not working some times.

But I just decided that I don't care anymore and manually disabled the venv for the root and fixed the others.

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

2 participants