更改在Jupyter Notebook中使用魔法命令设置的环境变量。

huangapple go评论61阅读模式
英文:

Change environment variable setted in jupyter Notebook with magics

问题

Sure, here's the translated content:

希望这个问题还没有得到答复,我已经搜索了很多帖子,但没有一个说如何更改环境变量。

我想要加载.env中的环境变量,所以按照这个帖子中的步骤进行操作。

%env "OPENAI_API_KEY"=OPENAI_API_KEY

然后,我想要查看我的变量:

%env OPENAI_API_KEY

一切都运行良好,但我的错误是错误地复制了我的环境变量的值。所以我想要更改它。

我尝试使用dotenv再次加载这个变量,但似乎不起作用。

希望你能帮助我,谢谢。

英文:

Hope this question is not already answered, I've searched many posts but none of them says how to change an environment variable.

I wanted to load environment variables in .env so followed the steps in this post.

%env "OPENAI_API_KEY"=OPENAI_API_KEY

Then I wanted to see my variable with:

%env OPENAI_API_KEY

Everything worked well but my mistake was to erroneously copy the value for my environment variable. So I want to change it.

I tried dotenv to load this variable again but seems not to work.

Hope you can help me, please.

I tried doing again the same procedure so that it can be changed/updated.

答案1

得分: 0

如果你写错了API密钥:

创建一个包含你的凭据的.env文件:

OPENAI_API_KEY="...错误的api密钥..."

你验证过了:

%env OPENAI_API_KEY

然后你意识到这是错误的。

你可以:

import os
del os.environ["OPENAI_API_KEY"]

然后:

os.environ["OPENAI_API_KEY"]="...正确的密钥..."

要验证这一点:

%env OPENAI_API_KEY

然后会提示更新后的API密钥。

英文:

If you made a mistake writing your APIKEY:

Created a .env with your credentials:

OPENAI_API_KEY="...erroneous-api-key..."

You verified:

%env OPENAI_API_KEY

And you realized it is wrong.

You can:

import os
del os.environ["OPENAI_API_KEY"]

Then:

os.environ["OPENAI_API_KEY"]="...right-key..."

To verify this:

%env OPENAI_API_KEY

And the updated api-key should be prompted.

huangapple
  • 本文由 发表于 2023年4月17日 21:13:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76035558.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定