Despite specifying a python.envFile
in workspace (.vscode/settings.json
), python.defaultInterpreterPath
does not seem to fetch the interpreter path via an environment variable, declared in the envFile
.
- File:
.env
# filename: .env
# set this in .vscode/settings.json:
# "python.envFile": "${workspaceFolder}/.env"
DEFAULT_INTERPRETER_PATH=path/to/python/interepreter
- File:
.vscode/settings.json
// filename: .vscode/settings.json
{
"python.envFile": "${workspaceFolder}/.env",
"python.defaultInterpreterPath": "${env:DEFAULT_INTERPRETER_PATH}",
"python.terminal.activateEnvironment": true,
"python.terminal.activateEnvInCurrentTerminal": false,
"jupyter.jupyterServerType": "local",
}
If I hard code the python.defaultInterpreterPath
, it works, and auto activates the interpreter, when I open a new terminal window. But it does not activate the the interpreter from the variable (in .env
file).
References
- https://code.visualstudio.com/docs/python/environments#_environment-variables
- In VS Code-debugger, how do I use envFile in launch.json for nodejs?
- https://www.youtube.com/watch?v=qTU7w3bWrOk&ab_channel=JonathanSoma
- This says you can only use the env variables from the
.env
file if you are debugging: https://www.reddit.com/r/vscode/comments/tkwooh/run_not_debug_python_using_the_env_file/ - https://github.com/microsoft/vscode-python/issues/11174