Creating true standalone applications in Python


You can use Python to create true standalone macintosh applications: applications that you can distribute to other people as a single file, without dependencies on Python being installed, etc. The process is not easy, however, and at the moment you need a source distribution (and a C development environment, CodeWarrior most preferred). You should first familiarize yourself with the sections building Python from source and building applets.

The application we are going to build will contain a complete interpreter, plus 'PYC ' resources for all the Python modules the program uses. We start by creating a resource file that contains all the modules we need, in PYC-resource form. There are two ways to do this:

Next we create the application project. Copy the PythonStandalone.prj project, replace macapplication.c by macapplet.c and replace bundle.rsrc by appletbundle.rsrc. Also add the PYC resource file you made in the previous step and any other resource files you need. Set the target output file names (for all three of ppc/68k/fat). Build your application.

Finally we have to give the application the right sys.path initialisation. We do this by dropping the application on EditPythonPrefs and removing all path components replacing them with a single $(APPLICATION). You may have to use ResEdit after this step to remove an "alis" resource from your application, I am not sure why this is sometimes created.

If you want to get fancy you may be able to make your application smaller by removing all unused builtin modules. If you used the findmodulefiles method above to find your modules you can start a standalone interpreter and use findmodulefiles.findunusedbuiltins to get the names of all builtin modules your program doesn't use. You can then create a private copy of config.c from which you remove all unused modules.