简体   繁体   中英

Needing to Reset Environment Variables in VirtualEnv Session

I am working on a Slack Bot and mostly followed this tutorial , except for some things that were different on Windows. One of these was setting the BOT_ID and SLACK_BOT_TOKEN environment variables. I used set BOT_ID=xcdsfsdf in a command prompt that was in a virtualenv session. Now that I've closed everything and returned to the project, BOT_ID and SLACK_BOT_TOKEN were no longer variables.

How can I set these variables so that I do not have to re-create them each time?

I could simply add these as system variables, but what if I was creating multiple slack bots? What is the standard practice? SLACK_BOT_TOKEN_1, SLACK_BOT_TOKEN_2, etc?

Additionally, when I go to reopen the project to run the python code, do I need to activate the virtualenv each time? Or can I just execute the python code?

Create a .env file in the root directory of your virtualenv and store your variables. I use it for django in this manner:

EMAIL_HOST_PASSWORD='some_password'
DJANGO_DEBUG=True
SECRET_KEY='a_complex_key'

The solution described in this other answer worked for me. Add the export lines to your bin/activate file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM