从命令行(Mac OS),当我执行'echo $ PYTHONPATH'时,我得到:
> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
如果我然后输入Python解释器并执行以下操作:
>>> import os
>>> os.environ['PYTHONPATH']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'PYTHONPATH'
为什么会发生这种情况?
答案 0 :(得分:2)
您忘记将其导出到环境中,以便子进程可以访问它;它目前只是一个bash变量。
export PYTHONPATH