Repository navigation
python.DefaultInterpreterPath not respected in multi-root workspace. #18207
Copy link
Copy link
Closed
Labels
area-environmentsFeatures relating to handling interpreter environmentsFeatures relating to handling interpreter environmentsbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug
Description
VS Code version
1.63.2
Extension version
v2021.12.1559732655
OS type
Windows
OS version
19043.1348
Python distribution
python.org
Python version
3.9.1
Language server
Pylance
Expected behaviour
When I set python.defaultInterpreterPath in my workspace configuration file, the Python extension should use that interpreter.
Actual behaviour
The "Choose a Python Interpreter" selection is shown and no interpreter has been selected.
Steps to reproduce
code-workspace settings file
{
"settings": {
"python.defaultInterpreterPath": "${workspaceFolder}/.virtualenvs/mtg_39_64/Scripts/python.exe",
}
}When attempting to clear the workspace interpreter setting (off a fresh restart) and resetting it via the command palette prompts, it does not work either.


Logs
And these are the results of my Python output. It appears to be not respecting the pre-defined ${workspaceFolder} variable. However, I've tried an absolute path as well, as well as my system-level Python paths and they do not work either (but no scandir errors are displayed).
Results
Experiment 'pythonaa' is active
Experiment 'pythonTensorboardExperiment' is active
Experiment 'pythonSurveyNotificationcf' is active
Experiment 'PythonPyTorchProfiler' is active
Experiment 'pythonDeprecatePythonPath' is active
> conda info --json
> "C:\Program Files\Python39\python.exe" ~\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py
> "C:\Program Files\Python38\python.exe" ~\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py
> ~\git\bitbucket\virtualenv\mtg_38_64\Scripts\python.exe -c "import sys;print(sys.executable)"
> ~\.virtualenvs\django-tutorial_39_64\Scripts\python.exe ~\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py
> ~\.virtualenvs\ugit_39_64\Scripts\python.exe ~\.vscode\extensions\ms-python.python-2021.12.1559732655\pythonFiles\interpreterInfo.py
> ~\git\bitbucket\virtualenv\mtg_38_64\Scripts\python.exe -c "import sys;print(sys.executable)"
Starting Pylance language server.
> ~\git\bitbucket\virtualenv\mtg_38_64\Scripts\python.exe -c "import sys;print(sys.executable)"
[ERROR 2021-11-19 16:25:49.126]: Diagnostic Code: InvalidPythonInterpreterDiagnostic, Message: No Python interpreter is selected. You need to select a Python interpreter to enable features such as IntelliSense, linting, and debugging.
Diagnostic Code: InvalidPythonInterpreterDiagnostic, Message: No Python interpreter is selected. You need to select a Python interpreter to enable features such as IntelliSense, linting, and debugging.
> conda --version
> ~\git\bitbucket\virtualenv\mtg_38_64\Scripts\python.exe -c "import sys;print(sys.executable)"
> ~\git\bitbucket\virtualenv\mtg_38_64\Scripts\python.exe -c "import sys;print(sys.executable)"
[ERROR 2021-11-19 16:27:12.152]: Python Extension: sendTelemetry [Error: ENOENT: no such file or directory, scandir 'C:\Users\Peter\AppData\Local\Programs\Microsoft VS Code\${workspaceFolder}\.virtualenvs\mtg_39_64\Scripts'] {
errno: -4058,
code: 'ENOENT',
syscall: 'scandir',
path: 'C:\\Users\\Peter\\AppData\\Local\\Programs\\Microsoft VS Code\\${workspaceFolder}\\.virtualenvs\\mtg_39_64\\Scripts'
}
Code of Conduct
- I agree to follow this project's Code of Conduct
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-environmentsFeatures relating to handling interpreter environmentsFeatures relating to handling interpreter environmentsbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug

Activity
kimadeline commentedon Dec 21, 2021
Hi Peter (@urscion), thank you for reaching out.
There are 2 things here:
There's a bug where we don't resolve
${workspaceFolder}when it's in thepython.defaultInterpreterPathsetting, thank you for reporting it 🙂I could not replicate your issue here, when I set a valid interpreter path in my
python.defaultInterpreterPathsetting in my workspace file it gets detected correctly:Does interpreter selection work correctly for you in non-multiroot workspaces?
brettcannon commentedon Feb 4, 2022
Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on then we will be happy to re-open this issue to pick up where we left off.
OmeGak commentedon Feb 14, 2022
I'm also experiencing this problem. Would it be possible to re-open this issue Brett Cannon (@brettcannon)?
The
python.DefaultInterpreterPathdefined in the global and workspace settings are completely ignored in multi-root workspaces. It only works unless it's defined in the.vscode/settings.jsonfiles.Kim-Adeline Miguel (@kimadeline) wrote:
Interpreter selection seems to work fine in non-multiroot workspaces. It works inconsistently in multi-root workspaces. Sometimes selecting interpreter from the dialog does nothing. When it works, it's not clear where this information is stored as it's not saved in the
workspace.jsonnor.vscode/settings.jsonfiles. Reloading window preserves the selected interpreter sometimes only.Kim-Adeline Miguel (@kimadeline) wrote:
Is there an issue already for this? It would be nice to be able to define
python.defaultInterpreterPathlike this in multi-root workspaces:kimadeline commentedon Feb 22, 2022
Hi Alejandro Avilés (@OmeGak),
Please provide repro steps, and ideally, a test repo I could use to try and replicate the issue on my end.
Support for
${workspaceFolder}was added in #18351. Does VS Code support${workspaceFolder:indico-un}system variables?OmeGak commentedon Feb 24, 2022
Hi Kim-Adeline Miguel (@kimadeline). Let me know if you can reproduce with these steps.
PIPENV_VENV_IN_PROJECT=1 pipenv install).python-a/foo.pyorpython-b/bar.py.python.defaultInterpreterPathdefined inworkspace.code-workspaceis ignored and VSCode reports an error:Additionally:
python.defaultInterpreterPathsetting on the interpreter selection dialog does nothing.The feature exists (https://code.visualstudio.com/docs/editor/variables-reference#_variables-scoped-per-workspace-folder) but it's not clear to me if it's available everywhere.
kimadeline commentedon Mar 1, 2022
Thank you for providing a test repo and steps!
${workspaceFolder}will change depending on which folder you're in. So, if you're inpython-a/foo.py,${workspaceFolder}/.venv/bin/pythonwill resolve topath/to/tmp-python-multiroot/python-a/.venv/bin/python, which doesn't exist after following the steps above. You can see the extension trying to resolve this path in the Python output panel:The only Python environment available is in
tmp-python-multiroot, not in any of the subfolders. Sincetmp-python-multirootis not a workspace folder, this environment is not picked up by the extension.If you want
${workspaceFolder}/.venv/bin/pythonto work, you need to create a.venvvirtual environment under every single one of your workspace folders.As for multiroot-workspace variable scoping, the extension does not support that at the moment. Feel free to open a feature request (and upvote it) to gauge community interest!
OmeGak commentedon Mar 3, 2022
Thanks for your response Kim-Adeline Miguel (@kimadeline)!
It was my impression that
${workspaceFolder}pointed to the directory where the workspace file is located in multi-root workspaces. Knowing now that it points to the actual project folder, I made it work on the test repo by setting:python.defaultInterpreterPathis then correctly respected and I consider this issue solved. Feel free to close it. 🎯This would nicely solve my real use case, which looks more like this:
To make it work with
defaultInterpreterPathI need to configure it like this:If multiroot-workspace variable scoping were available I could do the following instead:
Should I propose this in https://github.com/microsoft/vscode-python or https://github.com/microsoft/vscode?
kimadeline commentedon Mar 3, 2022
Glad to hear it woks now! And feel free to open this feature request on this repo (https://github.com/microsoft/vscode-python), and link to your comment above 🙂
Thank you!