1

UPDATE: I've now reset my .bash_profile to this (based on this blog post):

PYTHONPATH="${PYTHONPATH}:/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/:$PATH"
export PYTHONPATH

After that, I tried source activate again and received this error:

Failed to import the site module
Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python 3.x!
     PYTHONPATH is currently: ":/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/:/Users/name/anaconda/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/name/anaconda/bin:/Library/Frameworks/Python.framework/Versions/3.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/name/bin:/usr/local/git/bin:/Library/TeX/texbin"
     You should `unset PYTHONPATH` to fix this.

There is a major problem with this because that's not the PYTHONPATH set in my .bash_profile... Now, I proceeded to execute PYTHONPATH=/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/

However, I'm still getting this error even though I'm pointing to a 3.4 directory:

Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python 3.x!
     PYTHONPATH is currently: "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/"
     You should `unset PYTHONPATH` to fix this.

Using unset PYTHONPATH puts me in the same position noted below...


I use a macbook pro and typically operate with Python 3.X. Sometimes I need to use Python 2.7 and I have created an anaconda virtual environment to make it easy for me to do so. Since yesterday, I've started receiving 5 instances of the below error when trying to source activate my Python 2 virtual env within the command line:

Error in sitecustomize; set PYTHONVERBOSE for traceback:
KeyError: 'PYTHONPATH'

I executed the same command again as PYTHONVERBOSE=1 source activate python2 and located the Traceback (it's the same for each instance of the error):

Traceback (most recent call last):
  File "/Users/name/anaconda/lib/python3.4/site.py", line 508, in execsitecustomize
    import sitecustomize
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/usr/local/lib/python2.7/site-packages/sitecustomize.py", line 15, in <module>
    str(sys.version_info[0]) + '.x!\n     PYTHONPATH is currently: "' + str(os.environ['PYTHONPATH']) + '"\n' +
  File "/Users/name/anaconda/lib/python3.4/os.py", line 635, in __getitem__
    raise KeyError(key) from None
KeyError: 'PYTHONPATH'

Does anyone know how I may go about fixing this? I don't want to adjust any files before I fully know what I'm doing.

6
  • Why are you sticking $PATH into the value of PYTHONPATH? Commented Jan 24, 2016 at 23:38
  • How did install the virtual environment. Did you use python2 while install or python3 Commented Jan 25, 2016 at 9:02
  • @EtanReisner that was a mistake from a copy paste I did from a different path. Good catch. It still doesn't help if I remove it though...
    – Marto
    Commented Jan 25, 2016 at 13:12
  • @Transformer I used Anaconda.
    – Marto
    Commented Jan 25, 2016 at 13:12
  • Hmmm, And i gave you an answer for python Commented Jan 25, 2016 at 20:24

1 Answer 1

1

it looks like your PYTHONPATH is no longer set on your system, and the code is assuming that there is -something- in the environment.

I believe you could set a blank path in mac using the following; keep in mind if your python3.4 relies on the system path this may be dangerous! WARNING!: I am not on a mac, so you might need to give some string on the right-hand side here, otherwise it might not save the key

export PYTHONPATH=

If you do not want to set anything system-wide, you could simply add the variable to the running python scripts before sitecustomize runs. Buildout allows you to do this with a pre-script (via zc.buildout or zc.recipes, I am sure Anaconda has something similar), and this would allow the PYTHONPATH to be different for 3.4 and 2.7, which is what you're trying to do in the first place:

import os
pypath = os.environ.get("PYTHONPATH", "")
os.environ["PYTHONPATH"] = pypath

Not the answer you're looking for? Browse other questions tagged or ask your own question.