Partially invalid sys.path - how can I fix it (not append to it)?
Pierre Rouleau
prouleau001 at gmail.com
Mon Sep 28 11:19:53 EDT 2015
Hi,
On a OS/X 101.10.5 (Yosemite) system, the system Python just got updated to 2.7.10 but it sys.path is partially invalid. How can I fix that? I don't want to add something in PYTHONPATH. I know I can create a softlink at the invalid location to where the real files are located. I just want to understand why that sys.path[6] (see below) is invalid and fix it to point to the valid directory. Details follow:
I am running Python 2.7.10:
[~]$ python
Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
First, see when I get the sys.path before site.py is imported::
[~]$ python -S -c "import sys, pprint; print sys.prefix; pprint.pprint(sys.path)"
/usr
['',
'/usr/lib/python27.zip',
'/usr/lib/python2.7/',
'/usr/lib/python2.7/plat-darwin',
'/usr/lib/python2.7/plat-mac',
'/usr/lib/python2.7/plat-mac/lib-scriptpackages',
'/usr/lib/python2.7/../../Extras/lib/python',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload']
[~]$ python -c "import sys, pprint; print sys.prefix; pprint.pprint(sys.path)"
/usr
['',
'/usr/lib/python27.zip',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-darwin',
'/usr/lib/python2.7/plat-mac',
'/usr/lib/python2.7/plat-mac/lib-scriptpackages',
'/usr/Extras/lib/python',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/Library/Python/2.7/site-packages']
[~]$
Notice sys.path[6]. It is '/usr/lib/python2.7/../../Extras/lib/python', which when going through site gets normalized to '/usr/Extras/lib/python'. That directory is invalid on my system. It should either be:
- The real location: /System/Library/Frameworks/Python.frameworks/Versions/2.7/Extras/lib/python
or
- the corresponding softlink to that:
/usr/lib/python2.7/Extras/lib/python
Also note that the sys.prefix is "/usr"
I think it should be "/usr/lib/python2.7" or "/System/Library/Frameworks/Python.framework/Versions/2.7"
Other Python installed on that system include Python 3.5 (installed via the Python 3.5 DMG installer) and Python 2.7.9 installed with homebrew. For these versions of Python I see something that matches the content of the system storage:
- Python 3.5: sys.prefix = '/Library/Frameworks/Python.framework/Versions/3.5'
- Python 2.7.9: sys.prefix = '/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7'
Does anyone know how to fix the path generated in sys.path without adding the real directory path in PYTHONPATH?
Thanks!
More information about the Python-list
mailing list