I want to specify the Python path in tasks.json
without an explicit full path. I used to do this using python.pythonPath
, but that setting is now deprecated. What is the alternative way to retrieve the currently selected Python path? Are there any other VS Code environment variables?

- 25,369
- 29
- 96
- 135

- 377
- 1
- 9
-
1seems like `python.venvPath` / `python.defaultInterpreterPath`, [look](https://code.visualstudio.com/docs/python/settings-reference) – 0dminnimda Aug 31 '21 at 06:02
3 Answers
For the current python path, you need to select an interpreter and the currently used one is shown as a relative path in the box.
In tasks, have args called options so you can define env and PYTHONPATH there
You can find more details about tasks from the Tasks in Visual Studio Code documentation.

- 25,369
- 29
- 96
- 135

- 139
- 3
If you have the Python VSCode extension installed, and an interpreter is selected, then you can get the path to that interpreter in tasks.json using ${command:python.interpreterPath}
.

- 30,042
- 8
- 41
- 52
You can open VS Code command selector with ctrl + shift + p
and type "Python: Select Interpreter" to open a dropdown menu of all available interpreters. Doing this should create the appropriate entry to settings.json
(which was python.pythonPath
for me with version Python plugin version v2021.8.1159798656)
You can also change the interpreter from the bottom toolbar.

- 2,752
- 1
- 10
- 21
-
1This doesn't answer the question, OP needs a variable that can be used in the `tasks.json` file (or any other, I guess) that holds the path of the currently selected interpreter through that toolbar. `python.pythonPath` does not hold that value. – gjulianm Mar 23 '22 at 14:19