Python:无法访问新定义的环境变量 [英] Python: can't access newly defined environment variables
本文介绍了Python:无法访问新定义的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法访问我的环境变量:
I can't access my env var:
import subprocess, os
print os.environ.get('PATH') # Works well
print os.environ.get('BONSAI') # doesn't work
但是env var很好地添加到了我的/home/me/.bashrc
中:
But the env var is well added in my /home/me/.bashrc
:
BONSAI=/home/me/Utils/bonsai_v3.2
export BONSAI
我可以从新终端访问此环境变量.
And I can access this env var from a new terminal.
推荐答案
更新.bashrc
后,执行source ~/.bashrc
来应用更改.
After updating your .bashrc
, perform source ~/.bashrc
to apply the changes.
还将两个与BONSAI
相关的调用合并为一个:
Also, merge the two BONSAI
-related calls into one:
export BONSAI=/home/me/Utils/bonsai_v3.2
更新:实际上,这是试图为某些基于Eclipse的IDE更新环境的尝试.这是一个完全不同的用例. Eclipse 此处.
UPDATE: It was actually an attempt to update the environment for some Eclipse-based IDE. This is a different usecase altogether. It should be described in the Eclipse help. Also, a similar question was answered here.
这篇关于Python:无法访问新定义的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文