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
Issue opened on GitHub with VS Code
CodePudding user response:
i was facing issue of module not found in vscode then i wrote the same code in pycharm which was working there properly..so u can try pycharm
CodePudding user response:
You can use variable substitution in settings files, currently variables in environment files are not recognized.
You can also use an environment variable in the path setting using the syntax ${env:VARIABLE}. For example, if you've created a variable named PYTHON_INSTALL_LOC with a path to an interpreter, you can then use the following setting value:
"python.defaultInterpreterPath": "${env:PYTHON_INSTALL_LOC}",
Note: Variable substitution is only supported in VS Code settings files, it will not work in .env environment files.