Multi-root workspace: Python resolves imports only from venv of first root-folder #23448
Labels
bug
Issue identified by VS Code Team member as probable bug
triage-needed
Needs assignment to the proper sub-team
Type: Bug
Behaviour
In a multi-root workspace the Python virtual environment configured for the first folder dictates the virtual environment for all other folders used for import resolving even if different virtual environments are configured and displayed as active.
Looks similar to #14287 but this is marked as fixed since over a year.
Steps to reproduce:
Using Windows 10 with multiple Python installs, none of which is in the PATH, but py is installed. Git Bash as shell.
$ mkdir -p workspace_test/root_a $ mkdir -p workspace_test/root_b $ py -3.12 -m venv workspace_test/venv_a $ py -3.9 -m venv workspace_test/venv_b $ . workspace_test/venv_b/Scripts/activate (venv_b) $ py -m pip install --upgrade pip setuptools wheel [...] Successfully installed pip-24.0 setuptools-69.5.1 wheel-0.43.0
root_b
invenv_b
whilevenv_a
is kept clean.workspace_test/root_a
folder in VSCodeworkspace_test/root_b
to workspaceworkspace_test/root_a.code-workspace
dummy_a.py
inworkspace_test/root_a
root_a
, "Enter interpreter path"C:/path/to/workspace_test/venv_a/Scripts/python.exe
my_module_b.py
inworkspace_test/root_b
root_b
, "Enter interpreter path"C:/path/to/workspace_test/venv_b/Scripts/python.exe
root_a/dummy_a.py
=> status bar shows "Python 3.12.3 ('venv_a':venv)"root_b/my_module_b.py
=> status bar shows "Python 3.9.13 ('venv_b':venv)"root_b/my_module_b.py
(venv_b) ~/workspace_test/root_b $
(venv_b) ~/workspace_test/root_b $ py my_module_b.py COM1 COM2 ...
root_a
.(venv_a) ~/workspace_test/root_a $
from serial.tools import list_ports
is highlighted as with problems, tool tip showsvenv_b
also for theroot_a
folder, the imports inroot_b/my_module_b.py
are resolved fine. Selecting a Python interpreter on "workspace level" seems to have no effect.Diagnostic data
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)Output for
Python Language Server
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython Language Server
)Extension version: 2024.6.0
VS Code version: Code - Insiders 1.90.0-insider (a48f464a3e01aad384703ec964018299b14bb7cf, 2024-05-17T05:48:43.687Z)
OS version: Windows_NT x64 10.0.19045
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: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
A/B Experiments
The text was updated successfully, but these errors were encountered: