Reputation: 142
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. I'm working on a Windows machine with VS-code.
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?
Upvotes: 4
Views: 13820
Reputation: 601
The default Terminal that popped up for me in VS Code was the PowerShell, which I didn't realize at first. I had to use:
To write the env variable
$Env:MYAPP_DB_USER = "myapp_user"
To read the env variable
$Env:MYAPP_DB_USER
NB: '$' in front is part of the command. 'MYAPP_DB_USER' is the Key and 'myapp_user' is the Value I don't want to keep the passwords and keys as part of the code (including .env file) and have it pushed to the git repo and the server.
Ref: Microsoft PowerShell - Env variables
Upvotes: 2
Reputation: 59
go to endowment variable folder enter Script folder now activate with cmd
Upvotes: 0
Reputation: 4366
If you want to setup your development environment in VSCode you can simply add .env
file with all secrets defined in project root directory. More details in docs
Upvotes: 7
Reputation: 533
Your first solution
set CLIENT_SECRET=MYSECRET
in activate.bat
should work, when using Command Prompt in the terminal as Default Shell.
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.
Upvotes: 2