gpt4 book ai didi

python - 在 .venv 中设置环境变量

转载 作者:行者123 更新时间:2023-12-02 05:47:54 39 4
gpt4 key购买 nike

我正在使用 .venv 创建一个用于项目的虚拟环境。在这个项目中,我需要访问 OpenAI GPT3 环境。为此,我有一个 API key ,但我想将其存储为环境变量。因为我使用windows和VS-Code来处理我的项目,所以很多尝试都失败了。有谁知道如何解决这个问题?

最佳答案

你可以在settings.json文件中这样修改系统环境:

  "terminal.integrated.env.windows": {
"OPENAI_API_KEY": "xxx"
},

并将此添加到 .env 文件中:

OPENAI_API_KEY=xxx

When the terminal settings are used, PYTHONPATH affects any tools thatare run within the terminal by a user, as well as any action theextension performs for a user that is routed through the terminal suchas debugging. However, in this case when the extension is performingan action that isn't routed through the terminal, such as the use of alinter or formatter, then this setting will not have an effect onmodule look-up.

When PYTHONPATH is set using an .env file, it will affect anything theextension does on your behalf and actions performed by the debugger,but it will not affect tools run in the terminal.

可以引用official docs了解更多详情。

关于python - 在 .venv 中设置环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70660265/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com