Repository navigation
Description
Does this issue occur when all extensions are disabled?: I suspect so, can't figure out how to test. I would need an in-built vscode command that returns a string and for some reason am struggling to find one. I first noticed the issue using vscode-python and it has already been raised there: microsoft/vscode-python#19265. They suggested that it's an upstream problem and to raise here.
- VS Code Version:
Version: 1.71.0 (system setup)
Commit: 784b0177c56c607789f9638da7b6bf3230d47a8c
Date: 2022-09-01T07:36:10.600Z
Electron: 19.0.12
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Windows_NT x64 10.0.19044
Sandboxed: No
- OS Version: Windows_NT x64 10.0.19044
Steps to Reproduce:
- Either: install python extension or find a vscode command that returns a string and can be used as a command variable, as per these docs.
- Create a tasks.json file something like:
{
"version": "2.0.0",
"tasks": [
{
"label": "python: run",
// I think the issue only arises for type 'process'
"type": "process",
// This command could potentially be an in-built vscode one but I can't find one
"command": "${command:python.interpreterPath}"
}
]
}- Run the task
- Observe the output in the terminal, I get the following:
The terminal process failed to launch: Path to shell executable "C:\projects\ots\testVscodeWorkspace\C:\Python310\python.exe" does not exist.
Suspected Cause
I've been looking into this a bit and I think I might know why it's happening. Apologies if this is hard to follow:
- There is a call in
ExtHostTask.$resolveVariablestowin32.findExecutable. The executable it is trying to find is the string"${command:python.interpreterPath}". - It doesn't think this looks like an absolute path, so it prepends it with the current working directory (see the very end of the
win32.findExecutable) function. It doesn't check if this exists or not. - Later on, there is further variable resolution done by the
VariableResolverclass interminalTaskSystem.ts. This resolver has the details needed to expand the interpreter path correctly, but it has already been prepended with the cwd.
Proposed Solutions
-
Perhaps the
win32.findExecutablefunction could check if the executable exists at the location, and if it doesn't, simple return the unaltered process name (in this case"${command:python.interpreterPath}")? -
Alternatively, perhaps this call could be somehow removed from the setup done in
ExtHostTask? -
Perhaps the path could be resolved before running it - if there are two absolute paths then the right-most one could be used.
Activity
karrtikr commentedon Jul 25, 2023
Here're concise steps that can be used to reproduce the issue:
Steps to reproduce:
Please clone this repo https://github.com/pe224/vscode-python-venv-bad-path
All preparatory steps are indicated in the README.
interpreterPathfails withThis is the bug - seems like the workspace folder is prefixed to the actual (correct) venv python path.
barsikus007 commentedon Jan 11, 2024
any updates on that issue?
nylnx commentedon May 28, 2024
I would be very interested in a fix as well... Currently we have to duplicate all our tasks with a separate special "Windows version" because of this :(
And using
"shell"instead of"process"is not an option since the escaping of quotation marks is so horribly, horribly broken for tasks...Daddelhai commentedon Dec 13, 2024
Any update yet? Running into the same issue
tpajenkamp-dspace commentedon Jan 29, 2025
This issue also prevents the use of
${command:python.interpreterPath}if the selected Python interpreter is not in a virtual environment:unawarez commentedon Mar 27, 2025
Still broken with the same python.interpreterPath use case. I would really like to not use shell so that I don’t have to worry about quoting.
anthonykim1 commentedon May 27, 2025
Does using shell type like:
work better for people?
nylnx unawarez Yeah, it seems like there needs to be some work done to better handle escaping quotes for
shelltype tasks.Is it just the starting and the ending double quote that is giving you trouble or some things additional?
Thomas Pajenkamp (@tpajenkamp-dspace) Does running
C:\Temp\python\WorkingFolder\C:\Python312\python.exe+ script your intending to run by itself in the terminal work for you?tpajenkamp-dspace commentedon May 28, 2025
Anthony Kim (@anthonykim1) Of course the command also does not work in the terminal, the two paths
C:\Temp\python\WorkingFolderandC:\Python312\python.exeare not supposed to be combined.By the way, recent versions of VS Code constructs the path
C:\Temp\python\WorkingFolder\"C:\Python312\python.exe", which also does not work.A task like
{ "label": "myscript", "type": "shell", "command": "&'${command:python.interpreterPath}'", "args": ["myscript.py"] }works for powershell (no space after the ampersand and make sure to surround the executable path with single quotes), even though I would prefer a solution that is independent of any specific shell syntax.
DetachHead commentedon Jun 1, 2025
you can define OS-specific configs like this:
{ "label": "myscript", "type": "shell", "windows": { "command": "&'${command:python.interpreterPath}'" }, "linux": { "command": "${command:python.interpreterPath}" // (or whatever works on linux, i've only tested this on windows) } }tpajenkamp-dspace commentedon Jun 2, 2025
That's a good start. However, I would recommend something like this which highlights the need for a more general solution:
Preserve unresolved variables in process task command path (fixes mic…