[Pythonmac-SIG] sys.path on Leopard

Brian Granger ellisonbg.net at gmail.com
Thu Nov 1 20:45:18 CET 2007


Hi,

I have been playing around with python on Leopard today.  Overall, I
am very pleased, but I just ran into a problem that will affect a
large number of users.

In Leopard, Apple includes a number of python packages in:

ls /System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python

CoreGraphics				easy_install.pyc			setuptools-0.6c7-py2.5.egg-info
OpenSSL					fetchmailconf.py			site.py
PyObjC					fetchmailconf.pyc			site.pyc
PyObjC.pth				fetchmailconf.pyo			site.pyo
PyRSS2Gen-1.0.0-py2.5.egg-info		libsvn					svn
PyRSS2Gen.py				macholib				twisted
PyRSS2Gen.pyc				macholib-1.2.1.dev-py2.5.egg-info	wx
Twisted-2.4.0-py2.5.egg-info		modulegraph				wx-2.8-mac-unicode
Twisted_Words-0.4.0-py2.5.egg-info	modulegraph-0.7.2.dev-py2.5.egg-info	wxPython
Twisted_Xish-0.4.0-py2.5.egg-info	numpy					wxPython_common-2.8.4.0-py2.5.egg-info
altgraph				numpy-1.0.1-py2.5.egg-info		wxaddons
altgraph-0.6.8.dev-py2.5.egg-info	pkg_resources.py			wxaddons-2.8.4.0-py2.5.egg-info
bdist_mpkg				pkg_resources.pyc			wxversion.py
bdist_mpkg-0.4.3.dev-py2.5.egg-info	py2app					wxversion.pyc
bonjour					py2app-0.4.1.dev-py2.5.egg-info		xattr
bonjour_py-0.2-py2.5.egg-info		pyOpenSSL-0.6-py2.5.egg-info		xattr-0.5-py2.5.egg-info
dateutil				python_dateutil-1.2-py2.5.egg-info	zope
easy_install.py				setuptools				zope.interface-3.3.0-py2.5.egg-info

At first I was very excited to see that Apple is including things like
setuptools, numpy, twisted......

But then I saw that some of the versions are quite old.  Naturally, I
grabbed the latest numpy version from svn and did a python setup.py
install.  Everything built just fine, but when I did an import numpy,
I got Apples version:

>>> import numpy
>>> print numpy.__file__
/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/numpy/__init__.pyc

After looking at sys.path, it became clear what the problem is:

Running python setup.py install on Leopard causes packages to be
installed in the usual:

/Library/Python/2.5/site-packages

But, Apple put this directory _after_

/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python

in sys.path.  This, even if a user installs a newer version of one of
these packages, the builtin  python will always use Apple's older
version.

Obviously, I can set PYTHONPATH to get
/Library/Python/2.5/site-packages earlier in the sys.path list, but
this is going to bite many people.  Is this a bug that I should report
to Apple, or is there a better work around?  Also, this information
needs to be posted somewhere so we don't see this question a billion
times on various lists over the lifetime of Leopard.

Cheers,

Brian


More information about the Pythonmac-SIG mailing list