Dark Fighter free for a limited time
 

Dark Fighter

Now FREE on the App Store!

 
Gravit universal binary released for Mac OS X
 

Gravit released for OS X

A free Gravity Simulator

 
TowerDefend is now $0.99!
 

Tower Defend - ON SALE

Price reduced to 0.99 USD!

 

Creating an OS X Installer for Python modules and extensions

Creating an OS X Installer for Python modules and extensions 

In the past, people have hassled me to make it easier for them to install my applications and libraries on OS X. I’m not very skilled with OS X, and searching for how to do this task took some time. I’ve made a script that does this in a modular way for Python. Specifically, this article describes the process of making a Python module or extension installer for OS X, similar to the Python installer for Windows.

I use a Python module called bdist_mpkg which does most of the work. It simply creates a “mpkg” file out of your distribution by reading your standard distutils setup.py file. You can run it using either the command “bdist_mpkg” or as part of running setup.py, i.e. “python setup.py bdist_mpkg”. They both seem to do the same thing. The generated file is an OS X metapackage used by the OS X installer, “Installer.app”.

Once you have the mpkg file, which is generated in the directory “dist”, the script puts it in a “dmg” file. Putting a mpkg into a dmg file seems to be the standard way of distributing applications on OS X, yet I haven’t found out exactly why–someone point me in the right direction!

The script uses hdiutil to create a new, empty disk image then attaches (mounts) it to your system as a “device”. The attach command outputs the location of the path and device in the file system, which the script saves for detaching. Now that the image is mounted, the mpkg file is put into the image. The script then detaches (unmounts) then compresses the dmg file.

Unfortunately I didn’t save the references I used to find out the code to do this so I haven’t given credit, even though this is probably straightforward to an experienced OS X Python developer. The script, which I’ve called “python-osx-dist.sh”, accepts a package name and a version number as arguments. The script source is here and downloadable here, and am happy to get comments or patches for it.

One Comment

  1. joseph says:

    Hi,

    Thanks for pointing this out. The script source and download are not accessible (404 file not found) … at least on July 19, 2012

Leave a Comment