The goal is to make an app that uses wxPython and MySQLdb work on any 10.4 or 10.5 machine (both PowerPC and Intel). Our first attempt, built on a 10.5 machine, resulted in an app that worked only on 10.5. So I followed these steps to prepare a fresh 10.4 machine for the job:
Noted that the directions at http://www.python.org/download/mac were completely bogus -- despite the claims on this page, the link given for 10.4 leads to a distribution which is neither the latest nor a Universal Binary. Went instead to http://pythonmac.org/packages/py25-fat, but that also is out of date (installs 2.5.0 rather than 2.5.4). Finally found http://www.python.org/download/releases/2.5.4/, which links to http://www.python.org/ftp/python/2.5.4/python-2.5.4-macosx.dmg. Downloaded that and ran the installer. Opened a new Terminal window, and entered "python" to verify that it was 2.5.4. Within Python, tried "import wx" to verify that wx is not installed.
Went to http://wxpython.org/download.php, and scrolled to the "Binaries" section. Under Mac OS X, clicked the link for "Python 2.5", "osx-unicode" version. This was: http://downloads.sourceforge.net/wxpython/wxPython2.8-osx-unicode-2.8.9.1-universal-py2.5.dmg Mounted the disk image and ran the installer on the boot volume. Re-launched Python in a terminal window, and did "import wx" followed by "wx.__version__" to verify that wx was installed and at version 2.8.9.1.
Went to http://dev.mysql.com/downloads/mysql/5.1.html, and navigated to the Mac OS X "package format" downloads. But none of those are Universal Binaries (important if you're going to be building Python apps that need to be universal). However, under "TAR packages" there is a universal binary for 10.4: http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.30-osx10.4-universal.tar.gz/from/pick I was prompted to "log in" but there is a tiny "just take me to the download" link below which avoids that. This produced a .tar.gz file; double-clicked in the Finder to unpack. Found the "INSTALL-BINARY" file therein; but its instructions for creating the mysql group and user do not work on OS X. But this shouldn't matter as OS X already has a "mysql" user built in. So adapted the instructions as followed:
cd /usr/local ln -s mysql-5.1.30-osx10.4-universal mysql cd mysql sudo chown -R mysql . sudo chgrp -R mysql . sudo scripts/mysql_install_db --user=mysql sudo chown -R root . sudo chown -R mysql data bin/mysqld_safe --user=mysql &
That last command should actually launch the mysql server, which shouldn't be necessary if this is just a development machine used to make MySQL client apps (that connect to servers elsewhere). I did it anyway, and it complained repeatedly about permission denied on the error file. That doesn't make sense to me, since mysql owns that directory, but since I don't need to run the server anyway, I'm going to ignore it for now.
This is a utility used almost universally in the Python community in much the same way that "make" is used in the C/C++ community. Why it's not installed with Python by default, I can't imagine. Searched for setuptools at http://pypi.python.org. That led to http://pypi.python.org/pypi/setuptools/0.6c9, which includes instructions for downloading and installing. The correct download for 2.5 would be: http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c9-py2.5.egg#md5=fe67c3e5a17b12c0e7c541b7ea43a8e6 In Terminal, had it install itself with:
sh setuptools-0.6c9-py2.5.egg
This appeared to run successfully, installing itself in /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/.
This is the Python module that accesses MySQL databases. The instructions to follow here are at: http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/ Per these instructions, I downloaded the MySQLdb 1.2.2 tar file, and unpacked it with "tar xzvf MySQL-python-1.2.2.tar.gz". Step 3 failed, because I didn't have setuptools installed. (See above; and if you have to go back and do that as I did, be sure to create a new terminal window before continuing.) With setuptools installed, step 3 failed for a different reason: "mysql_config not found". Apparently we need to add the mysql directory to our search path: edit ~/.profile, and add lines such as:
PATH="$PATH:/usr/local/mysql/bin" export PATH
Close and reopen the Terminal window, and do "which mysql_config", and it should report /usr/local/mysql/bin/mysql_config. Then we go back to the MySQLdb instructions and try step 3 again, and this time it worked. Hacked _mysql.c per the instructions (step 4). Made a silly symbolic link (step 5). I don't think step 6 is necessary, since mysql_config is in our search path now (since when it wasn't, step 3 failed). Ran "sudo python setup.py build" per step 7. This did generate some scary-sounding warnings, but the instructions say to ignore them. Now, step 8 may require care, since we want to install the package in such a way that py2app won't choke on it (as it does with standard zipped "egg" packages). ...Couldn't find any way to avoid that (it creates a ".egg" file, which is really a zip file). Needed to manually unpack it, like so:
python-src> cd /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ site-packages> mv MySQL_python-1.2.2-py2.5-macosx-10.3-i386.egg MySQL_python-1.2.2-py2.5-macosx-10.3-i386.zip site-packages> mkdir MySQL_python-1.2.2-py2.5-macosx-10.3-i386.egg site-packages> mv *.zip MySQL_python-1.2.2-py2.5-macosx-10.3-i386.egg/ site-packages> cd MySQL_python-1.2.2-py2.5-macosx-10.3-i386.egg MySQL_python-1.2.2-py2.5-macosx-10.3-i386.egg> unzip *.zip
Verified the installation by opening a new Terminal window, launching python, and doing:
import MySQLdb MySQLdb.__version__ '1.2.2'
A one-liner:
sudo easy_install -U py2app
We already had a setup.py file from our earlier attempt on 10.5, so I moved into my project directory, and did "python setup.py py2app". This resulted in an app bundle (though it was missing most of the python files and all of the resources -- we manually moved those in before, and I had to do so again; I guess our setup.py file still needs some work). After manually moving the needed files into the bundle, it launches and runs fine on my 10.4 and 10.5 Intel machines. So that's some progress. But on a 10.4 PPC machine, it fails at launch saying:
ImportError: dlopen(/Users/jstrout/Temp/etownCentral.app/Contents/Resources/lib/python2.5/lib-dynload/_mysql.so, 2): Symbol not found: _mysql_get_host_info Referenced from: /Users/jstrout/Temp/etownCentral.app/Contents/Resources/lib/python2.5/lib-dynload/_mysql.so Expected in: dynamic lookup
So after all that work, I *still* don't have a properly universal app. (Note that I was careful to download and install the universal binary of mysqldb above.)
Author: Joe Strout
Date Published: 2009-01-06
Making a Macintosh .app that runs on both 10.4 and 10.5 in Python Making a Macintosh .app that runs on both 10.4 and 10.5 in Python Making a Macintosh .app that runs on both 10.4 and 10.5 in Python
[email protected] [email protected] [email protected] [email protected] [email protected]