-
Notifications
You must be signed in to change notification settings - Fork 2
Build On Mac
How to build the program on a Mac from source and bundle it into an application using py2app.
This page will give instructions on how to set up Mac OS X so that you can run the program from source and then how to bundle the code into a stand alone application so that it can be distribute to users who don't need to to anything to install it.
In order to build this program on a Mac running OS X, you will need to install a bunch of stuff. First, you need to install Xcode. Actually, I am not really sure if this is necessary, because I think the only thing I use it for is to install gcc. So it is probably possible to avoid this step by installing gcc another way. But I haven't actually tried doing this. You need to install Python. I got a copy of the latest version of Python through the MacPython package system. I first went to http://pythonmac.org/packages/ MacPython and installed the python2.5 version of Python, Numeric, and the PIL. I then build Pmw from source. its not actually hard at all to do. The only tricky part is that the version linked to directly on the Pmw website didn't build for some reason. Instead, I installed from the latest version (Pmw 1.3.2) which you can get at the sourceforge page. Once you download it, you just have to untar it, open it up, and then do a
$ sudo python setup.py install
This gets us everything we need to run the program. We first have to build the C extensions that I wrote that the program needs to run. We can no go into the AreaDiffractionMachine's source folder and then into the wrap/ folder. If you issue the command
$ sudo python setup.py install
it will build the extensions. To run the program then, you can go into the main source folder and issue the command:
$ python AreaDiffractionMachine.py
This should be everything you need to run the program from source
In order to bundle this program into a stand alone application, I am using the program py2app. We are going to need to first install py2app from source. The easiest way to do so is to first install this easy_install python program which you can use to install other packages easily. got it from ez_setup guy's website by downloading the hosted file named ez_setup.py program. I then installed it using the command
$ sudo python ez_setup.py
This installed the easy_install program into my path, so that I could use it to easy install these python scripts. To install py2exe (but first its dependencies), I issued the command:
$ sudo easy_install macholib
$ sudo easy_install setuptools
$ sudo easy_install bdist_mpkg
$ sudo easy_install modulegraph
$ sudo easy_install altgraph
$ sudo easy_install py2app
Unfortunately, this dose not install a recent enough version of modulegraph or macholib or py2app to work properly. When you just issue these commands, py2app makes this annoying error which was supposedly fixed in a later release. To get around this, you can install modulegraph from source using the latest build in the SVN repository. To do so, you can using the command
$svn checkout http://svn.pythonmac.org/modulegraph/modulegraph/trunk/
And them moving into the trunk and issuing the command
$ sudo python setup.py install
We can then install macholib
$ svn checkout http://svn.pythonmac.org/macholib/macholib/trunk/
and then going into the trunk and issuing
$ sudo python setup.py install
Now, lets install the newest version of py2app:
$ svn checkout http://svn.pythonmac.org/py2app/py2app/trunk/
followed by
$ sudo python setup.py install
Once you have installed all this stuff, you can then go into my SVN build folder and issue the command
sudo python setup_mac_version1.py py2app --iconfile=landeBMWIcon.icns
The --iconfile will create an icon fror the program and the .app file will be put into a dist/ folder. There is some magic done inside so that at the end of the day all you are left with is a disk image in the same folder named "Area Diffraction Machine.dmg"
You can build the program into a stand alone executable which will run on any mac using the python package py2app. BUilding it is easy because I wrote a script that does all the hard work. To run the script, go into the build/ folder and issue the command
sudo python setup_mac_version1.py py2app --iconfile=landeBMWIcon.icns --version=X.X.X
The version string "X.X.X" should be replaced with whatever version you are building - like "1.0.1", or whatever. The script will build the program into a .app executable, rename the .app file to have the version name in it, and then compress the file into a .dmg file for easy distribution. Once the script is done, you can do whatever you want with the executable. Pretty easy!