Python 2.7 module path problems on OS X

Ned Deily nad at acm.org
Sun Sep 5 15:57:41 EDT 2010


In article 
<AANLkTim4fk9Y2MaBs3H14Z+5RKBxtgmP27VyvMkQEwS+ at mail.gmail.com>,
 Nicholas Cole <nicholas.cole at gmail.com> wrote:

> On Sun, Sep 5, 2010 at 10:20 AM, Ned Deily <nad at acm.org> wrote:
> > 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.
> >
> Sorry. I wasn't clear.  Of course I understand that each version of
> python needs its own additional packages, and I was expecting to
> re-install them.  But I don't want to install system-wide --  I'd like
> to have my own, user-specific, site-packages.  On previous versions of
> python, I've  installed into
> ~/Library/Python/$py_version_short/site-packages under my home
> directory.
> 
> In my recollection, this has worked in the past for python installed
> from python.org, but perhaps that recollection is wrong.  At any rate,
> it doesn't  work with python 2.7.

Ah, my apologies.  I overlooked the "~/Library" part.  So what you have 
been using is the setuptools Mac OS X "User" Installation configuration:
(http://peak.telecommunity.com/DevCenter/EasyInstall#mac-os-x-user-instal
lation).   Yes, it seems an incompatibility has been introduced in 2.7 
for OS X.  There has been an on-going and as yet unresolved discussion 
on the python-dev list about the topic of user directory and config file 
locations so things will likely change and get more consistent in the 
future.  But this particular problem is more immediate.  I believe the 
problem here is that the default user directory path was changed between 
2.6 and 2.7 from:

    ~/Library/Python/m.n/site-packages

to

    ~/Library/Python/m.n/lib/python/site-packages

I will track that down further and open an issue for it, if necessary.  
In the meantime, here's a little snippet that I think should work around 
the problem for the moment without requiring a change to your 
configuration files.  (For simplicity of installation, it uses the 
Distribute fork of setuptools).  The main point is to create a symlink 
between the old and new locations. Let me know if this works for you:

$ cat .pydistutils.cfg 
[install]
install_lib = ~/Library/Python/$py_version_short/site-packages
install_scripts = ~/bin
$ rm -r ~/Library/Python/2.7 # REMOVES ANY EXISTING LOCAL PACKAGES
$ mkdir -p ~/Library/Python/2.7/lib/python/site-packages
$ ( cd ~/Library/Python/2.7 ; ln -s lib/python/site-packages 
site-packages )
$ curl -s http://python-distribute.org/distribute_setup.py -o 
/tmp/distr.py
$ python2.7 /tmp/distr.py 
Extracting in /var/folders/pD/pD-bOKKQHluYv0YkNWJhPE+++TI/-Tmp-/tmpF5sVf7
Now working in 
/var/folders/pD/pD-bOKKQHluYv0YkNWJhPE+++TI/-Tmp-/tmpF5sVf7/distribute-0.
6.14
Installing Distribute
[...]
$ ~/bin/easy_install
easy_install      easy_install-2.6  easy_install-2.7  
$ ~/bin/easy_install-2.7 appscript
[...]
$ python2.7 -c "from appscript import *;print(app('Finder').version())"
10.5.8
$ ls -l ~/Library/Python/2.7
total 8
drwxr-x---  3 nad  staff  102 Sep  5 12:20 lib/
lrwxr-x---  1 nad  staff   24 Sep  5 12:20 site-packages@ -> 
lib/python/site-packages
$ ls -L ~/Library/Python/2.7/site-packages
appscript-0.21.1-py2.7-macosx-10.3-fat.egg/ easy-install.pth
distribute-0.6.14-py2.7.egg/                setuptools.pth

-- 
 Ned Deily,
 nad at acm.org




More information about the Python-list mailing list