From the command line (Mac OS), when I execute 'echo $PYTHONPATH' I get:
> /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
If I then enter the Python interpreter and do the following:
>>> 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'
Why would this happen?
asked Sep 30, 2012 at 19:24
nucklehedd
3011 gold badge3 silver badges12 bronze badges
-
1Why would your PYTHONPATH be set to a location that Python searches anyway?Keith– Keith2012年09月30日 22:30:29 +00:00Commented Sep 30, 2012 at 22:30
-
Remember the contents of $PYTHONPATH get appended to sys.path automatically, but they should also appear in os.environ (probably is as the first answer indicates).Perkins– Perkins2012年09月30日 23:31:21 +00:00Commented Sep 30, 2012 at 23:31
1 Answer 1
You forgot to export it to the environment so that subprocesses can access it; it's currently only a bash variable.
export PYTHONPATH
answered Sep 30, 2012 at 19:27
Ignacio Vazquez-Abrams
804k160 gold badges1.4k silver badges1.4k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py