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 file. You can run it using either the command “bdist_mpkg” or as part of running, i.e. “python bdist_mpkg”. They both seem to do the same thing. The generated file is an OS X metapackage used by the OS X installer, “”.

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 “”, 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 thought on “Creating an OS X Installer for Python modules and extensions”

  1. 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 Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>