sultan
sultan

Reputation: 6058

Fabric: unable to get environment variables within virtualenv

I've a Django project which runs in virtual environment. Also there is line export ENV=staging in .bashrc file. And in settings I try to read this using 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 may cause the problem or what is goin wrong with?

Sultan.

Upvotes: 3

Views: 2386

Answers (2)

mnowotka
mnowotka

Reputation: 17228

There is one more case when fabric ignores .bashrc. Often .bashrc contains following line:

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

Comment it out.

Upvotes: 10

Tomasz Wysocki
Tomasz Wysocki

Reputation: 11568

Common problem is that .bashrc file is never executed. Type env and check if ENV variable is there.

Upvotes: 3

Related Questions