py2app is a Python distutils suite which provides several useful features for distributing Python applications and libraries on the Mac OS X platform. The py2app suite contains the following packages:
Any components of the py2app suite may be distributed under the MIT or PSF open source licenses.
Note that the installer for PyObjC 1.2 ships with py2app 0.1.7.
An installer for py2app 0.1.8 may be downloaded from:
The source to py2app 0.1.8 may be downloaded here:
py2app maintains a public subversion source code repository currently located at:
As of version 0.1.6, py2app uses the extra_path feature of distutils, which changes the installation layout. If you have py2app 0.1.5 or earlier installed, you must manually remove the following directories from your site-packages directory (probably /Library/Python/2.3) if they exist before upgrading:
How do I use py2app?
py2app is a distutils command that is used in a similar manner to py2exe. For your application, you must create a Python script (conventionally named setup.py) that looks like the following:
#!/usr/bin/env python
"""
setup.py - script for building MyApplication
Usage:
% python setup.py py2app
"""
from distutils.core import setup
import py2app
setup(
app=['MyApplication.py'],
)
When running this script as directed, py2app will do the following:
Process the command line for arguments. The arguments accepted by the py2app command can be enumerated using the following command line:
% python setup.py py2app --help Global options: ... (these are available from any distutils command) Options for 'py2app' command: ... (these are specific to py2app) usage: ... (this is a generic distutils usage message)
Note that any of the options accepted on the command line may also be used in your setup.py script! For example:
#!/usr/bin/env python
"""
setup.py - script for building MyApplication
"""
from distutils.core import setup
import py2app
# Note that you must replace hypens '-' with underscores '_'
# when converting option names from the command line to a script.
# For example, the --argv-emulation option is passed as
# argv_emulation in an options dict.
py2app_options = dict(
# Map "open document" events to sys.argv.
# Scripts that expect files as command line arguments
# can be trivially used as "droplets" using this option.
# Without this option, sys.argv should not be used at all
# as it will contain only Mac OS X specific stuff.
argv_emulation=True,
# This is a shortcut that will place MyApplication.icns
# in the Contents/Resources folder of the application bundle,
# and make sure the CFBundleIcon plist key is set appropriately.
iconfile='MyApplication.icns',
)
setup(
app=['MyApplication.py'],
options=dict(
# Each command is allowed to have its own
# options, so we must specify that these
# options are py2app specific.
py2app=py2app_options,
)
)
Issue the distutils build command
Analyze the application for Python dependencies
Make sense of the dependencies
Create the application bundle
Make the application bundle standalone
What recipes does py2app come with?
Locates and includes all plugins that ship with docutils (languages, parsers, readers, writers)
Removes several dependencies that are only used when running the pydoc web server or Tkinter GUI (Tkinter, tty, BaseHTTPServer, mimetools, select, threading, ic, getopt).
Includes the whole pygame package as-is, so that it will locate its data files correctly. This recipe may be improved in the future if pygame undergoes appropriate modifications.
Locates and includes all image plugins (Python modules that end with ImagePlugin.py), removes unwanted dependencies on Tkinter.
Includes the whole pyOpenGL package as-is, so that it can read its version file during __init__.py. This recipe may be improved in the future if PyOpenGL undergoes appropriate modifications.
Includes the whole py2app package as-is, so that it has copies of the executable and plugin templates. This recipe may be improved in the future if py2app undergoes appropriate modifications.
If ANY extension that uses sip is detected, include all extensions that use sip. This is necessary because sip generates C code to do its imports, and is thus not trackable by bytecode analysis. The only package known to use sip is PyQt, so what this means is that if you use any of PyQt, then all of it will be included.
Note that recipes are developed on an as-needed basis, and coverage of every single Python library is not possible. If you have trouble with a particular library, please let us know.
The following packages are known to need recipes, but none currently exist:
The workaround is to include PEAK using the packages option.
These C libraries require data files and environment variables set up. A workaround exists, but one has not yet been written and tested.
A data_files option to include a resource file must be added to setup.py:
#!/usr/bin/env python
"""
setup.py - workaround for wxPython 2.4.x
Usage:
% python setup.py py2app
"""
from distutils.core import setup
import py2app
setup(
app=['test.py'],
data_files=[('../Frameworks', [
'/usr/local/lib/libwx_mac-2.4.0.rsrc',
]
)],
)
XXX
XXX
By default, the following tools are installed to /usr/local/bin:
A convenient way to run the bdist_mpkg distutils command. Equivalent to editing the setup.py in the current directory to import bdist_mpkg and running the following command:
python setup.py bdist_mpkg --open
If any options are given, then they are given in place of --open.
By default, the following GUI tools are installed to /Developer/Applications/Python Tools/py2app:
Copyright (c) 2004, 2005 Bob Ippolito <bob at redivi.com>.