[Pythonmac-SIG] Bug: Apps built with py2app on Leopard will default to import system-default libraries

Nathan nathan.stocks at gmail.com
Thu Mar 6 06:34:35 CET 2008


After much discussion on the pyglet and twisted mailing lists, I've
isolated a bug in py2app's handling of sys.path on Leopard.

Scenario:

A custom installation of a python package is installed in
/Library/Python/2.5/site-packages or elsewhere.  The environment is
set to use that package first, either by default (in the case of the
former) or by some other means that both the script to be py2app'd and
py2app understand.

Behaviour:

py2app pulls in the custom library into the .app into
site-packages.zip or (in the case of -p some.package) into
Resources/lib/python2.5/some/package, but when the resulting .app is
executed, those locations occur in sys.path after all the customary
system locations, so the system installed versions are used first.

Example:

I've installed Twisted 2.5 and Zope 3.something into
/Library/Python/2.5/site-packages (the default location when you run
'python setup.py install').  py2app correctly identified the need for
twisted and included it in site-packages.zip.  py2app did not
correctly identify the need for the custom Zope install, so I added it
via the command line (python setup.py py2app -p zope).

Because of the nature of the bug, I was able to work around it by
manually inserting the relative path to the custom versions that
py2app placed inside the app:

import sys
sys.path.insert(0,'../Resources/lib/python2.5/site-packages.zip')  #
Now twisted 2.5 is found instead of the system's twisted 2.4
sys.path.insert(0,'../Resources/lib/python2.5/')  # Now the custom
zope install is found instead of the system's zope.

~ Nathan


More information about the Pythonmac-SIG mailing list