Python 2.7 module path problems on OS X

Ned Deily nad at acm.org
Sun Sep 5 05:20:24 EDT 2010


In article 
<AANLkTi=zZGOmi5NhYZCa7X9RBWu==oQzrZr4S876K2Eg at mail.gmail.com>,
 Nicholas Cole <nicholas.cole at gmail.com> wrote:

> I have a horrible feeling that this is in some way related to the new
> user installation directory in 2.7,or some problem with the framework
> built, but I'm having great trouble with the module search path on
> 2.7.
> 
> I usually install modules to install_lib =
> ~/Library/Python/$py_version_short/site-packages

There are differences in defaults between different Python versions and 
instances of the same version as built by different providers.   The 
pattern above is the default location for site-packages for 
Apple-supplied Pythons in recent versions of OS X, in particular the 
default /usr/bin/python2.6 in OS X 10.6 and /usr/bin/python2.5 in 10.5.  

>> I assumed that this would continue to work on 2.7.
> 
> Unfortunately, it seems not to. The installation is fine, but sys.path
> only includes
> 
> '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
> '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
> '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
> '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
> '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-
> scriptpackages',
> '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
> '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
> '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
> '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
> '

OTOH, the Python instances installed by the python.org OS X installers 
(or ones built similarly) default to using the site-packages directory 
in the framework directory as shown in that last path.

> Whereas on 2.6 on my system the default is the more extensive:
> 
[...]
> 
> I'm sorry to ask such a trivial question on the list, but I'm used to
> python installations "Just working"!  Can anyone suggest a good fix?

I'm not sure why you think it is broken.  The Apple 2.6 and the 
python.org 2.7 have different site-package directories in different 
locations.  That is to be expected.  The Apple-supplied Python comes 
with some additional packages pre-installed, like setuptools, PyObjC, 
and wx.  But you would need to install new versions of these for 2.7 
anyway.

f you use "easy_install" (aka setuptools or Distribute), keep in mind 
that every instance of Python needs to have its own version.  So, for 
2.7, you should follow the installation instructions for either 
setuptools or Distribute and install a version for 2.7 using python2.7.  
Its easy_install command will be in the framework bin directory, 
/Library/Frameworks/Python.framework/Versions/2.7/bin, which is the 
default location for scripts to be installed.  You should ensure that 
that directory appears on your shell PATH before /usr/bin (where the 
Apple-supplied easy_install is); if you used the default settings for 
the python.org installer, it will have attempted to modify your shell 
startup files, like .bash_profile, to do that for you.  Then you can use 
that easy_install (also available as easy_install-2.7) to install 
whatever packages you need for 2.7.  Or you can use pip.  Or just 
manually installing using the package's setup.py script.  All of them 
use the Python instance's version of Distutils and it will do the right 
thing for each instance as long as you don't try to influence things by 
using non-default settings or setting Python-related environment 
variables, like PYTHONPATH.

-- 
 Ned Deily,
 nad at acm.org




More information about the Python-list mailing list