【发布时间】:2022-06-13 14:17:49
【问题描述】:
尽管在工作区 (.vscode/settings.json) 中指定了 python.envFile,python.defaultInterpreterPath 似乎并未通过在 envFile 中声明的环境变量获取解释器路径。
- 文件:
.env
# filename: .env
# set this in .vscode/settings.json:
# "python.envFile": "${workspaceFolder}/.env"
DEFAULT_INTERPRETER_PATH=path/to/python/interepreter
- 文件:
.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",
}
如果我对python.defaultInterpreterPath 进行硬编码,它可以工作,并在我打开一个新的终端窗口时自动激活解释器。但它不会从变量中激活解释器(在.env 文件中)。
参考文献
- 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
- 这表示如果您正在调试,您只能使用来自
.env文件的环境变量:https://www.reddit.com/r/vscode/comments/tkwooh/run_not_debug_python_using_the_env_file/ - https://github.com/microsoft/vscode-python/issues/11174
使用 VS Code 在 GitHub 上打开的问题
【问题讨论】:
-
一旦用户为工作区明确选择了不同的解释器,Python 扩展将不会获取对 python.defaultInterpreterPath 的更改。Reference documentation。
-
@JialeDu 谢谢你的评论。但这不是问题。硬编码路径被识别。不是通过环境变量引用的路径。
标签: python visual-studio-code environment-variables