Search code examples
python-3.xcmdvirtualenv

Python Virtual Environment Variables Not Saving


I have created a virtual environment for python and need to add some variable. I use

$set USERNAME = my_username

but when I close the cmd and re-open, the variable is gone. I read in Super User that closing the cmd is necessary here https://superuser.com/questions/79612/setting-and-getting-windows-environment-variables-from-the-command-prompt.

How do I save the variable so that it is still there after I deactivate my VE, then close out the cmd?

(I have tried doing this as both a user and admin)


Solution

  • Press Windows + R, type in sysdm.cpl and hit enter. You should now see a prompt titled "System Properties". Click on Advanced -> Environment Variables. You can see all the environment variables that are set on your machine. Hit add and add your USERNAME environment variable and set it to your value