[英]Set environment variables when activating python virtual environment in windows
I want to be able to set up environment variables in my virtual environment so that they are available in my code when I activate the virtual environment.我希望能够在我的虚拟环境中设置环境变量,以便在我激活虚拟环境时它们在我的代码中可用。 I make my virtual enviornments with venv.
我用 venv 制作我的虚拟环境。 I'm working on a Windows machine with VS-code.
我正在使用 VS 代码的 Windows 机器上工作。
What I already tried, but didn't work.我已经尝试过,但没有奏效。
set CLIENT_SECRET="MYSECRET"
$CLIENT_SECRET="MYSECRET"
export CLIENT_SECRET="MYSECRET"
I found a lot related to my topic, but none working for me.我发现了很多与我的主题相关的内容,但没有一个对我有用。 What to do?
该怎么办?
Your first solution您的第一个解决方案
set CLIENT_SECRET=MYSECRET
in activate.bat
should work, when using Command Prompt in the terminal as Default Shell.当在终端中使用命令提示符作为默认 Shell 时,
activate.bat
中的应该可以工作。
You can omit the quotes unless they are part of your envirionment variable.您可以省略引号,除非它们是您的环境变量的一部分。
You can verify, if the environment variable is set with:您可以验证是否设置了环境变量:
echo %CLIENT_SECRET%
in the terminal in VS-Code.在 VS-Code 的终端中
echo %CLIENT_SECRET%
。
转到禀赋变量文件夹输入脚本文件夹现在用 cmd 激活
在 CMD 终端中使用 set 使用 env: in powershell
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.