I'm working on a Django project and want to set the DJANGO_SETTINGS_MODULE environment variable in my virtualenv. All the solutions I can find on the internet use UNIX shell commands, and I'm running Windows 10. How can I set the environment variable? I'm using virtualenvwrapper if that makes a difference.
How can you set environment variables in a virtualenv in Windows?
Asked Answered
Inside of your virtual environment locate the Scripts\activate.bat script. There you can add some commands to initialize shell variables with the set command. For your project, you may want something like
set DJANGO_SETTINGS_MODULE=settings.local
Once you deactivate the virtual environment, the environment variable will persist and may conflict with that of another environment. Thus, it is good practice to unset environment variables in virtual environments. You can do this by adding the following to the Scripts\deactivate.bat script.
set DJANGO_SETTINGS_MODULE=
Cool. Will this also unset the environment variable when I deactivate the virtualenv? –
Caucus
© 2022 - 2024 — McMap. All rights reserved.