VS代码“ Python.envfile”似乎与“ python.defaultinterPreterPath”似乎不起作用。

发布于 2025-02-06 18:05:23 字数 2044 浏览 2 评论 0 原文

尽管在工作区( .vscode/settings.json.json )中指定了 python.envfile ), python.defaultInterPreterPath 似乎不是通过通过解释器路径通过解释器路径通过环境变量,在 envfile 中声明。

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

在GitHub上使用VS代码

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一百个冬季 2025-02-13 18:05:23

您可以在设置文件中使用变量替换,目前未识别环境文件中的变量。

您还可以使用语法$ {env:variable}在路径设置中使用环境变量。例如,如果您创建了一个名为Python_install_loc的变量,则可以使用以下设置值:

 “ python.defaultinterpreterpath”:“ $ {env:python_install_loc}”,
 

注意:可变替换仅在VS代码设置文件中支持,它将在.env环境文件中不起作用。

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.

一场信仰旅途 2025-02-13 18:05:23

我认为这里至少有两个可能的误解。

  1. 在所有设置中不支持变量替换 - 仅在某些设置中,我不知道 python.defaultinterpreterpath 是其中之一。

  2. 从我的理解中, } 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.

  1. 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.

  2. 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's envFile mechanism does not modify the environment of the VS Code process, but instead child processes. The documentation states:

    Environment variable definitions files can be used for scenarios such as debugging and tool execution (including linters, formatters, IntelliSense, and testing tools), but aren't applied to the terminal.

    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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文