Fabric: Unable to get environment variables in virtualenv

I have a Django project that works in a virtual environment. There is also a line export ENV=stagingin the .bashrcfile. And in the settings, I'm trying to read this with os.getenv('ENV'), but it returns None.

settings_staging.py

...
ENV = os.getenv('ENV')
...

.bashrc

...
export ENV=staging
...

Error

[dev.gipi] out:   File "/home/ubuntu/projects/deeyoon/settings/settings.py", line 61, in <module>
[dev.gipi] out:     raise Exception('Environment variable ENV is requried!')
[dev.gipi] out: Exception: Environment variable ENV is requried!

What can cause the problem or what is going wrong?

Sultan.

+3
source share
2 answers

A common problem is that the .bashrc file is never executed. Enter envand check if the variable ENV is present.

+3
source

There is another case where the fabric ignores .bashrc. Often .bashrc contains the following line:

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

Comment on this.

+10
source

All Articles