Fabric:无法在virtualenv中获取环境变量

时间:2022-09-13 00:15:12

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.

我有一个在虚拟环境中运行的Django项目。在.bashrc文件中还有行导出ENV = staging。在设置中我尝试使用os.getenv('ENV')读取它,但它返回None。

settings_staging.py

settings_staging.py

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

.bashrc

的.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.

苏丹。

2 个解决方案

#1


3  

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

常见问题是.bashrc文件永远不会被执行。输入env并检查ENV变量是否存在。

#2


10  

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

当fabric忽略.bashrc时,还有一种情况。通常.bashrc包含以下行:

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

Comment it out.

评论出来。

#1


3  

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

常见问题是.bashrc文件永远不会被执行。输入env并检查ENV变量是否存在。

#2


10  

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

当fabric忽略.bashrc时,还有一种情况。通常.bashrc包含以下行:

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

Comment it out.

评论出来。