Home > Blockchain >  VS Code "python.envFile" does not seem to work with "python.defaultInterpreterPath&qu
VS Code "python.envFile" does not seem to work with "python.defaultInterpreterPath&qu

Time:06-13

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.

  1. File: .env
# filename: .env
# set this in .vscode/settings.json:
# "python.envFile": "${workspaceFolder}/.env"
DEFAULT_INTERPRETER_PATH=path/to/python/interepreter
  1. 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

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.

  • Related