Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After installing Anaconda, I get constant "KeyError: 'PYTHONPATH'" messages

After installing Anaconda for Python 3.4 on my Mac I get constant messages saying:

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

As suggested by a user on another question, I used

PYTHONVERBOSE=1 conda update --all

And received the traceback:

Traceback (most recent call last):
  File "/Users/user/anaconda/lib/python3.4/site.py", line 506, 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/user/anaconda/lib/python3.4/os.py", line 633, in __getitem__
    raise KeyError(key) from None
KeyError: 'PYTHONPATH'
# destroy sitecustomize

I have looked around and found that 'PYTHONPATH' does not exist as a key in os.environ.

like image 642
Mackie Blackburn Avatar asked Sep 01 '15 00:09

Mackie Blackburn


2 Answers

If your PYTHONPATH environment variable is set, unset it. You can check with echo $PYTHONPATH. If it is set it is probably coming from something in ~/.profile or ~/.bash_profile.

The issue is the file /usr/local/lib/python2.7/site-packages/sitecustomize.py. You may want to check what that file is and where it comes from, but removing it should fix the problem.

like image 102
asmeurer Avatar answered Oct 04 '22 01:10

asmeurer


Going to necro-answer here with more detail for folks that might hit this page after searching for the error shown…

If your Mac has messages referencing /usr/local/, I'm going to go ahead and assume you've used homebrew to install something. In this case, Python.

When Anaconda's Python distribution is installed, one of the things it'll check is if there are any site customizations applied to your existing Python installation. If you installed any version of Python using Homebrew, you likely have such a site customization.

  1. Running conda info -a | grep dirs will get your Anaconda install info and look for a line with dirs included. Only one should match, if it exists:

    user site dirs: ~/.local/lib/python3.5

  2. If it does exist, cd to that directory (whatever it is), and get a directory listing (ls). You'll then (likely) find a file called homebrew.pth.

  3. Remove that file, and the error goes away.

Reason: Anaconda is referencing that homebrew.pth file, which then goes on to include the sitecustomize.py from your earlier homebrew-installed version of Python.

like image 26
Dustin Avatar answered Oct 04 '22 00:10

Dustin