VS代码“ Python.envfile”似乎与“ python.defaultinterPreterPath”似乎不起作用。
尽管在工作区( .vscode/settings.json.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
当我打开一个新的终端窗口时。但是它不会从变量(in .env
文件)中激活解释器。
References
- https://code.visualstudio.com/docs/python/environments#_environment -Variables
- “>在vs code-debugger中 =“ nofollow noreferrer”> https://www.youtube.com/watch?v=qtu7w3bwrok&ab_channel=jonathansoma
- 这只能说您只能使用
.env> .env
.env File> File> File> File> File> File> File> File> File> File> File>。如果您要进行调试:
在GitHub上使用VS代码
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在设置文件中使用变量替换,目前未识别环境文件中的变量。
You can use variable substitution in settings files, currently variables in environment files are not recognized.
我认为这里至少有两个可能的误解。
在所有设置中不支持变量替换 - 仅在某些设置中,我不知道
python.defaultinterpreterpath
是其中之一。从我的理解中, } mechanism is for referencing variables from the environment of the VS Code process itself, and
当然,我还没有排除我可能会误解我读过的内容,但这是我从阅读的内容中理解。
I think there are at least two possible misunderstandings here.
Variable substitution is not supported in all settings- only in select ones, of which I am not aware of
python.defaultInterpreterPath
being one of them.From my understanding, the
${env:VARIABLE_NAME}
mechanism is for referencing variables from the environment of the VS Code process itself, and the python extension'senvFile
mechanism does not modify the environment of the VS Code process, but instead child processes. The documentation states:The situation with application to the terminal (and related run features that use the terminal like the run button at the top right) might be changing. See Use environment variables defined in .env file when running code in a terminal
#944.
Of course, I haven't ruled out that I could have misunderstood what I've read either, but this is my understanding from what I've read.