vscode-python: Having relative paths in .code-workspace files for interpreter path setting doesn't work
Environment data
- VS Code version: 1.45.1
- Extension version (available under the Extensions sidebar): 2020.5.80290
- OS and version: Windows 7 Enterprise
- Python version (& distribution if applicable, e.g. Anaconda): 3.7.0
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv
- Relevant/affected Python packages and their versions: n/a
- Relevant/affected Python-related VS Code extensions and their versions: n/a
- Jedi or Language Server? (i.e. what is
"python.jediEnabled"
set to; more info #3977): Language Server - Value of the
python.languageServer
setting: Microsoft
Expected behaviour
{
"python.pythonPath": "..\\.venv\\Scripts\\python.exe",
}
I expect this to be able to use a parent virtual environment as the editor’s environment. I also tried ${workspaceFolder}/../.venv
. I am trying to use the multi-root workspace feature with a full-stack app scaffold I work with for maintainability in my editor experience.
Setting pythonPath
in the .code-workspace
also seems to have no effect.
Actual behaviour
I receive generic extension crash modals and a re-prompt to select my python environment. The crash was intermittent, but it always re-prompts for a python interpreter.
Steps to reproduce:
[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]
PowerShell MVP setup script:
#requires -Version 3
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
$root = "${PWD}\repro-example"
$niParams = @{
Path = "$root\src\server\.vscode", "$root\src\client"
ItemType = 'Directory'
Force = $true
}
New-Item @niParams > $null
@'
{
"folders": [
{"path": "."},
{"path": ".\\src\\server"},
{"path": ".\\src\\client"}
]
}
'@ | Out-File -FilePath "$root\vscode.code-workspace"
@'
{
"python.pythonPath": "..\\.venv\\Scripts\\python.exe",
"python.jediEnabled": false,
}
'@ | Out-File -FilePath "$root\src\server\.vscode\settings.json"
'' | Out-File -FilePath "$root\src\server\__init__.py" -NoNewline
py.exe -3 -m venv "$root\.venv"
code.cmd "$root\vscode.code-workspace"
Logs
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
Starting Microsoft Python language server.
> c:\Users\maximilian\repos\repro-example\src\.venv\Scripts\python.exe c:\Users\maximilian\.vscode\extensions\ms-python.python-2020.5.80290\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> c:\Users\maximilian\repos\repro-example\src\.venv\Scripts\python.exe c:\Users\maximilian\.vscode\extensions\ms-python.python-2020.5.80290\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
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.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18
Feature request from VSCode: https://github.com/microsoft/vscode/issues/98424
Another upstream issue you may relate to https://github.com/microsoft/vscode/issues/77718
Please upvote these if you would like that.
The correct solution should be to resolve relative paths in
.code-workspace
files against the location of the workspace file.