Python, Qt4 and a Mac OS X 10.4 .app

Posted on December 2nd, 2008 by raoul and tagged , , , , , .

So after my last attempt to compile Qt4 on my Mac, and getting the same error repeatedly, I decided to submit a bug report. One of the guys at Trolltech replied to my bug report, and asked me a number of questions, including "Have you completely removed your previous installation of Qt4?"

Of course I have, I thought, but I decided to go and double check everywhere. Lo and behold I found some files I'd forgotten about. So then I decided to recompile Qt4 again, and was very glad to see that it worked! A make and sudo make install later, I had Qt4 installed.

Now that I'd gotten the hurdle of compiling Qt4 over, it was back to my previous problem: PyQt4. This time, however, I had no problems at all. Everything configured and compiled fine. Now I could get back to the real reason I was wanting to have PyQt4 installed on my Mac: openlp.org. So for the last week or so, I've been happily poking at openlp.org in quiet moments at work, happy that I have PyQt4 working again.

One other thing that I wanted to do was to work out how to compile openlp.org into a Mac OS X .app bundle. I downloaded and installed py2app, a Python setup tool to convert Python apps into Mac OS X .app bundles. After going through the documentation and creating my setup.py file, I ran the compile command:

python setup.py py2app

Sadly, when I tried running the resulting openlp.app bundle, it died with an error that said something to the effect of "can't find sip." SIP is the Python module that helps PyQt4 connect to Qt4. I was stumped.

Then, last night in openlp.org's IRC channel, ALok told me to check out a blog post about using py2app to create PyQt4 bundles.

I checked out the blog post, but the guy on there said that one should install Python, Qt4 and PyQt4 from MacPorts. No thank you. I've just gone through a whole lot of trouble to compile and install Qt4 and PyQt4, and now you want me to do it again? I decided to just try out the setup.py file he had there, and stick with my compiled stuff here.

On first try, Python complained about an unknown module called "PyQt4._qt." But shouldn't that be just plain "PyQt4"? I thought. Sure enough, when I modified setup.py to use PyQt4, it worked!

Here's my version of setup.py:

from setuptools import setup

APP = ['openlp.pyw']
OPTIONS = {'argv_emulation': True, 'includes': ['sip', 'PyQt4']}

setup(
    app=APP,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)