[Pythonmac-SIG] semi_standalone option broken in py2app + Leopard Python?

Robin Dunn robin at alldunn.com
Tue Jul 1 17:45:36 CEST 2008

Ronald Oussoren wrote:
> Note that py2app needs a considerable amount of attention though:
> * need enhancements to properly support eggs:
>   - copy entire eggs into the .app bundle, instead of just bits and pieces
>   - support the "entry-point" feature for eggs
>   - an option to specify required eggs in setup.py (like setup_requires, 
> but for a specific app)

Just yesterday I implemented a bit of post setup() code that allows me 
to inject some eggs into my app bundle after it has been created.  First 
I specify the egg's package name in the packages option so py2app will 
include the package and do dependency checks on it, but not put it in 
the zip file.  Then after setup() has run I remove these package 
folders, copy in the egg folders (none of mine are zipped but that 
should probably work too) and then create a sitecustomize.py in the app 
to add the eggs to the sys.path.  This last step is needed because it 
looks like the normal .pth file processing is not included in the 
site.py used in the app bundle.

Here is a bit of the code from my setup.py, the two names used in the 
for loop items are because some eggs use a different egg name than the 
package name.

     makingAlias = '-A' in sys.argv or '--alias' in sys.argv
     if not makingAlias:
         base = 'dist/%s.app/Contents/Resources/lib/python%s' % (NAME, 
         sc = file(os.path.join(base, 'sitecustomize.py'), 'w')
         sc.write("import sys, os\nbase = os.path.dirname(__file__)\n")
         for distname, pkgname in [('Foo', 'foo'),
                                   ('Bar', 'bar'),
                                   ('xyz', 'xyz')]:
             dist = pkg_resources.get_distribution(distname)
             distbase = os.path.basename(dist.location)
             remove_tree(os.path.join(base, pkgname))
             copy_tree(dist.location, os.path.join(base, distbase), 
update=1, verbose=1)
             sc.write("sys.path.append(os.path.join(base, '%s'))\n" %

This probably isn't enough to use as a base for general purpose egg 
support in py2app, but it can at least be used as a stopgap measure 
until somebody who knows what they are doing can add support for it in 
the right way.

Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!

More information about the Pythonmac-SIG mailing list