Repository navigation
Wrong python interpreter selected in multiroot workspaces when debugging using ${command:python.interpreterPath} #18482
Description
Activity
- addedtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
on Feb 8, 2022 - addedarea-editor-*User-facing catch-allUser-facing catch-allbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugand removedtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
on Feb 9, 2022 Hi Guillaume Racicot (@gracicot), thank you for reaching out.
You shouldn't have to specify the
pythonline in your launch.json config, if the virtual environment is selected for that specific folder it should get picked up automatically.${command:python.interpreterPath}is also an incorrect value.What happens if you remove the
pythonline from your launch.json config?- addedinfo-neededIssue requires more information from posterIssue requires more information from poster
on Feb 9, 2022 Kim-Adeline Miguel (@kimadeline) Seems like it's working without the
pythonline. Strangely, the value${command:python.interpreterPath}works very well with a single root workspace. Thanks for pointing out the problem. I'm just unsure how I'm wrong. The python extension allows us to select the python interpreter from the status bar, I figured I had to choose that interpreter to be in line with what's displayed in the editor.After digging deeper in the code, we do support
${command:python.interpreterPath}. However, when using it we make an assumption that there will be aworkspaceFolderargument with the path to the workspace folder, and use that to determine the correct Python path:vscode-python/src/client/debugger/extension/configuration/launch.json/interpreterPathCommand.ts
Lines 30 to 42 in 33476c4
public _getSelectedInterpreterPath(args: { workspaceFolder: string } | string[]): string { // If `launch.json` is launching this command, `args.workspaceFolder` carries the workspaceFolder // If `tasks.json` is launching this command, `args[1]` carries the workspaceFolder const workspaceFolder = 'workspaceFolder' in args ? args.workspaceFolder : args[1] ? args[1] : undefined; let workspaceFolderUri; try { workspaceFolderUri = workspaceFolder ? Uri.parse(workspaceFolder) : undefined; } catch (ex) { workspaceFolderUri = undefined; } return this.configurationService.getSettings(workspaceFolderUri).pythonPath; } This assumption is incorrect, since this argument isn't there. This will result in us trying to get the first Python path we can get our hands on (because of the
undefinedvalue), which is fine in single-workspace scenarios, but, as you noticed, doesn't work so well for multi-root workspaces.tl;dr: It's a bug on our end, thank you for reporting it!
Reacted by Serge Matveenko- added and removedinfo-neededIssue requires more information from posterIssue requires more information from poster
on Feb 9, 2022 7 remaining items
I'm not on the Python team anymore, but I'll let them know that it's an acute pain point for you 🙂
Serge Matveenko (@lig) https://github.com/microsoft/vscode-python/suites/15205238033/artifacts/868956057 fixes the issue described in #18482 (comment), try installing it using
Install from VSIXcommand and see if it helps.Reacted by Serge MatveenkoReacted by Serge Matveenko- added a commit that references this issue
on Aug 17, 2023 Kartik Raj (@karrtikr) No effect, sorry. I needed to install code-insiders and I've checked that Python v2023.15.5895828483-dev extension is installed.
It looks like it uses a venv defined in the first folder for anything unconditionally now ignoring any folder specific interpreter configuration.
I see, the cause stated in #18482 (comment) should be fixed, it's likely that there's another bug in addition to that. As a workaround try removing
"python": "${command:python.interpreterPath}",
in your
launch.jsonfrom all workspace folders, let me know if that helps.I have only one
launch.jsonfile and it doesn't havepythonkey.So, now it always uses the first folder's venv for everything except stdlib packages. Using "go to definition" on stdlib packages results in opening a file from system default interpreters' library.
I think I can share my entire workspace with you as it contains only Open Source projects at the moment.
Or maybe some logs would be enough?
This issue is related to
${command:python.interpreterPath}, if you don't have"python"set, maybe your issue is different and you're not referencing this command at all? In that case please open a new issue usingPython: Report Issuecommand and we'll be happy to have a look.Btw note you need to create separate
launch.jsonfor each workspace folder if you wish to use selected interpreter for each folder:Each
launch.jsonwill only be run using the folder's selected interpreter in which thatlaunch.jsonfile exists.Reacted by Serge MatveenkoI believe the original issue #18482 (comment) should be fixed with #21835, hence I'm closing this. If it isn't please let us know and we'll be happy to have a look again.
- changed the title
[-]Wrong python interpreter selected in multiroot workspaces when using ${command:python.interpreterPath}[/-][+]Wrong python interpreter selected in multiroot workspaces when debugging using ${command:python.interpreterPath}[/+]on Sep 6, 2023 - added a commit that references this issue
on Sep 12, 2023 - locked as resolved and limited conversation to collaborators
on Oct 7, 2023

Issue Type: Bug
Behaviour
Expected vs. Actual
Expected:
importstatements works.Actual:
importstatements for packages installed inside the venv don't work.Steps to reproduce:
Create a workspace with the following files:
Here's the content of each files:
python-bug.code-workspace:{ "folders": [ { "path": "project1" }, { "path": "project2" } ] }project1/project1.py:project2/.vscode/launch.json:{ "version": "0.2.0", "configurations": [ { "name": "project2", "type": "python", "request": "launch", "python": "${command:python.interpreterPath}", "program": "${workspaceFolder}/project2.py", "console": "integratedTerminal" } ] }project2/project2.py:project2/requirements.txt:python3 -m venv venvin the project2 terminalsource ./venv/bin/activatein the project2 terminalpip install -r requirements.txtvenvfolderpython project2.pyin the project2 console, it should run fineWorkaround
Setting the python interpreter to
${workspaceFolder}/venv/bin/pythoninlaunch.jsonsolves the problem, so it seem that the python plugin select the wrong interpreter.Diagnostic data
python.languageServersetting: PylanceUser Settings
Extension version: 2022.0.1814523869
VS Code version: Code 1.64.0 (5554b12acf27056905806867f251c859323ff7e9, 2022-02-03T04:20:17.224Z)
OS version: Darwin x64 20.6.0
Restricted Mode: No
System Info
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
webgl: enabled
webgl2: enabled
A/B Experiments