1

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?

2
  • 1
    Why would your PYTHONPATH be set to a location that Python searches anyway? Commented 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). Commented Sep 30, 2012 at 23:31

1 Answer 1

3

You forgot to export it to the environment so that subprocesses can access it; it's currently only a bash variable.

export PYTHONPATH
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.