SystemExit: Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python 3.x

Viewed 903

I was running into a problem while trying to install anaconda and python 3.7 on MacOS. After I installed anaconda, every time I open my Terminal, the following message shows up:

Fatal Python error: initsite: Failed to import the site module
Traceback (most recent call last):
  File "/Users/s/anaconda3/lib/python3.7/site.py", line 570, in <module>
    main()
  File "/Users/s/anaconda3/lib/python3.7/site.py", line 563, in main
    execsitecustomize()
  File "/Users/s/anaconda3/lib/python3.7/site.py", line 502, in execsitecustomize
    import sitecustomize
  File "/usr/local/lib/python2.7/site-packages/sitecustomize.py", line 16, in <module>
    '     You should `unset PYTHONPATH` to fix this.')
  File "/Users/s/anaconda3/lib/python3.7/_sitebuiltins.py", line 26, in __call__
    raise SystemExit(code)
SystemExit: Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python 3.x!
     PYTHONPATH is currently: "/usr/local/lib/python2.7/site-packages:"
     You should `unset PYTHONPATH` to fix this.

Of course I tried to unset the PYTHONPATH, but it doesn't work: every time I open up the Terminal again, the messages appears again. Can anyone help me with this issue?

Thank you for your help

1 Answers

If you loaded pythona and anaconda that helps a lot. After you load python3.7 be sure to type 'which python3.7' to get its location. Now you want to create a virtual environment for python3.7. Anaconda makes this easy. You can type the following commands on the terminal in your home directoty

conda create -n myenv python=3.7

where myenv is the name of your virtual environment. It can be any name you please. After that you must activate that environment by typing:

source activate myenv

After activating the environment just run python or python3 from the command line. It should work now. Additional instructions for creating a virtual environment using Anaconda can be found here or here. There are numerous other sites. Just google some combination of 'create virtual environment anaconda mac.

Related