Note: After nearly a year of compatibility problems, Nokia and Apple have released versions of Qt and Snow Leopard (respectively) that are able to run PyQt. This article explains how to install PyQt using the precompiled binaries available from the Nokia website and the PyQt bindings from Riverbank computing. Installation instructions for Leopard can be found here.
To install PyQt on Mac OS X Snow Leopard is a four step process. First, download and install the GCC compilers and associated utilities available in Apple’s XCode development environment. Second, install the Qt framework from Nokia. Third, download and compile the SIP binding generators from Riverbank computing. Finally, compile and install the PyQt bindings themselves.
XCode and Qt
The easiest way to get the most current version of the GCC compilers and associated tools is to download the XCode package from Apple at the Apple Developer Connection (ADC). ADC requires that you have an Apple ID and account, which are both free. After you log-in, download the XCode developer tools package. Given its size (nearly 1 GB), this may take awhile.
While waiting for the XCode tools to download, you can also begin downloading the Qt binary installer from the Trolltech downloads page. As of this writing (May 26, 2010), the only version of Qt that runs well on Snow Leopard is version 4.7. For that reason, I strongly suggest downloading the Qt 4.7.0 beta. (Do not download the Qt 4.7.0 Carbon version, as Apple is dropping support for Carbon in the near future. It is also believed that many of the previous compatibility issues were due to the deprecation of the Carbon frameworks.)
Once XCode has finished downloading, run the package installer. It will ask you to select the destination drive and what components of the software you would like to install.
This will automatically install and configure the GNU tool chain. Once it has finished, you can access the tools by going to the “/Developer/” folder on the root of the drive.
After XCode has finished, run the Qt installer.
The Qt installer package will automatically place the tools and other things that you will need in the same Developer folder where the XCode tools and frameworks are located. This includes the Qt developer tools, documentation examples and header files. If you only wish to run Qt programs, it is not necessary to install the documentation and examples and you can deselect them by clicking on the “Customize” button of the “Installation Type” panel.
SIP and PyQ
SIP is a program that makes it easy to create C++ bindings for Python. You can find the source code at Riverbank’s SIP download page. Since you will be using the 4.10 (or greater) of PyQt, you should probably download the latest developer snapshot (version 4.10 or greater). Be sure to get the Linux/Unix source code, rather than the Windows source. You will also need the latest source code snapshot for PyQt 4.7, which is also available from Riverbank.
After you have finished downloading the source files, move them to a folder in your Users directory. I have a special directory entitled “Applications” where I keep the source code for programs that I have manually compiled. Note: The rest of the steps will be done from the Mac OS X terminal.
After you have moved the source code for both SIP and PyQt to this new directory, extract it by using the tar utility with the x and f options (tar –xf):
tar -xf sip-snapshot-4.10-529660fb77a9.tar.gz
tar -xf PyQt-mac-gpl-snapshot-4.7.4-049020fd7d72b.tar.gz
After you have expanded the files, it might be a good idea to rename the directories to something more manageable (like sip-4.10 and PyQt4.7):
mv sip-snapshot-4.10-529660fb77a9.tar.gz sip-4.10
mv PyQt-mac-gpl-snapshot-4.7.4-049020fd7d72b.tar.gz PyQt4.7
First, we need to compile and install SIP. The default configuration will move the compiled files to a directory where Leopard can’t read them. So, we will manually need to specify the destination directory using the –d flag:
python configure.py –d /Library/Python/2.6/site-packages
After the configuration is finished, run make and sudo make install:
sudo make install
Once SIP has finished installing, we need to repeat the process for PyQt. From the sip-4.10 directory, change to PyQt:
Next, run the configuration script specifying the path to the installation directory for the python bindings:
python configure.py –d /Library/Python/2.6/site-packages/
Then compile and install:
sudo make install
Since Qt is a rather large framework, it may require between 15 and 30 minutes to fully compile.