2

I think this got foobarred when I was doing some brew update stuff. Everytime my system python3 is called, it emits:

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

This is particularly annoying because I use powerline in my terminal and powerline makes several calls to python each time I execute a command.

Calling Python3 with a the Verbose flag I get:

$ PYTHONVERBOSE=True python3

<multiple pages of python startup info...>

# possible namespace for /usr/local/lib/python2.7/site-packages/backports
# bytecode is stale for 'sitecustomize'
# code object from /usr/local/lib/python2.7/site-packages/sitecustomize.py
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 481, in execsitecustomize
    import sitecustomize
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, 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 "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/os.py", line 669, in __getitem__
    raise KeyError(key) from None
KeyError: 'PYTHONPATH'
# destroy sitecustomize
import 'site' # <_frozen_importlib_external.SourceFileLoader object at 0x101e3a630>

<more python startup info...>

So the system Python3 is trying to load the Python2 version of sitecustomize? I suspect that's the problem. If so, what are my options for fixing this? brew unlink python3 && brew link python3 didn't help.

I'm not sure what the bytecode is stale for 'sitecustomize' comment python is making is about, but I've also removed the sitecustomize.pyc file, which didn't help.

LiavK
  • 702
  • 6
  • 20
  • One interesting problem here is that you appear to be using Python 3.6 but it's importing 2.7's sitecustomize file. What does `env | grep PY` show? – John Szakmeister Apr 23 '18 at 23:55
  • Not much: PYTHONSTARTUP=/Users/liavkoren/.pythonstartup PYTHONDONTWRITEBYTECODE=true. I added dontwritebytecode years ago, and my .pythonstartup only has a shortcut for `from datetime import datetime` and `from pprint import pprint`. – LiavK Apr 24 '18 at 03:06
  • What is in .pythonstartup? What's craze here is that it's looking in very much the wrong location for sitecustomize... so it seems like a path is off somewhere. Like the location is being added through some mechanism (such as your .pythonstartup) or PYTHONPATH is being set directly (though I doubt this is the problem because of the KeyError you are seeing). – John Szakmeister Apr 24 '18 at 09:41
  • There's nothing relevant in my .pythonstartup. : ) – LiavK Apr 24 '18 at 13:18
  • I agree, it seems the problem is py3 trying to load a py2 sites.py. I don't know why that's happening, tho, or what good options to fix are. Should I just delete and install or do I need to track down a python path problem or..? – LiavK Apr 24 '18 at 13:19
  • I noticed that calling python with -s ("Don’t add the user site-packages directory to sys.path") prevents the KeyError. Exporting PYTHONNOUSERSITE in my bashrc file prevents the messages from being printed, although the shell prompt is still *noticably* slower than if was before this issue appeared. – LiavK Apr 24 '18 at 13:42
  • I don't think re-installing will help you. I suspect there's something else in your file system/environment/customizations that is being picked up that's causing the issue. I think the trick is tracking that down. Have you tried exporting PYTHONVERBOSE=2 (instead of True)? It'll show a little more about what is happening and might help you see where things are going sideways. I'd pay close attention to the python start up info. – John Szakmeister Apr 24 '18 at 13:58
  • It looks like it's search *many many* paths for python3 sitecustomize.py file before it finally tries the python2 version. Here's a gist with a longer, verbosity=2 sample: https://gist.github.com/liavkoren/0de6d0d48b840ee61a184c8181f45670 – LiavK Apr 24 '18 at 17:21
  • AFAICT, nothing is setting my PYTHONPATH. If I do an `echo $PYTHONPATH` in the shell, nothing is printed, and adding `unset PYTHONPATH` to .bashrc doesn't change anything. – LiavK Apr 24 '18 at 17:47
  • Wow... it looks to be heading to Python 2.7's stuff pretty early on. Alright, two more questions: do you have any .pth files anywhere? And, what does `python3 -c 'import sys; print(sys.path)'` show? – John Szakmeister Apr 24 '18 at 18:32
  • Result of both of those are in: https://gist.github.com/liavkoren/a430ca37a5f7ca62e8eb2dd6d257ed77 – LiavK Apr 24 '18 at 19:08
  • Just be be sure, I uninstalled pdbpp, which is the package that adds "_pdbpp_path_hack" to pythonpath. No change. – LiavK Apr 24 '18 at 19:09

0 Answers0