| May 27, 2010 1:28 pm

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.

Select the installation disc where you want to install XCode the developer tools

Choose the components 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 4.7 Installer

Select the installation destination

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.

Qt4.7 Install - Customize

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):

cd ~/Applications
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:

cd sip-4.8
python configure.py –d /Library/Python/2.6/site-packages

After the configuration is finished, run make and sudo make install:

make
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:

cd ..
cd PyQt4.7

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:

make
sudo make install

Since Qt is a rather large framework, it may require between 15 and 30 minutes to fully compile.

Comments

22 Responses to “Installing PyQt on Mac OS X (Snow Leopard)”

[…] Art and Photography « Installilng PyQt on Mac OS X (Snow Leopard) […]

Yarko wrote a comment on June 8, 2010

I seem to be having a problem…. it looks like it’s something to do (no doubt) with some previous attempt at install / build (which I no longer recall)…. somewhere / somehow, I’m getting the makefile populated with a library path of /tmp/qt-stuff/source/qt-everywhere-opensource-src-4.7.0-beta1/lib….

And it’s not just in this build (any clues appreciated).

[…] I’ve written about before.  For a guide to installing Qt and Qt creator on Mac, take a look at this post.  For Windows, instructions can be found […]

Courtney wrote a comment on July 7, 2010

I don’t know what I am doing except following your step by step instructions.

When I am to the point where I am doing ‘python configure.py -d /Library/Python/2.6/site-packages/’ and I get the error ImportError:No module named sipconfig what do I need to do to fix that?

I tried copying the sipconfig.py from the site-packages folder to the pyqt folder and it seemed to be working and configureing took about 20 minutes but then at the end of that it said

ld: symbol not found
collect2: ld returned 1 exit status
make[1]: *** [libythonplugin.dylib] error 1
make: *** [install]Error 2

I have follow all the steps and sip seemed to install no problem not sure how to test that, but there were no errors. I am trying to install a program (PySpline) and every time I do it says need to install PyQt first so i apparently haven’t installed it.

Any help is much appreciated.

Thanks

Rob Oakes wrote a comment on July 7, 2010

Hi Courtney,

I’m sorry to hear that you’re having so much trouble. What I”m going to say might sound a touch snide, that’s not how it’s meant. Anyhoo …

Take a couple of big, patient breaths. PyQt on Mac OS X is a mess. It has been since Snow Leopard was released, and even though I thought Qt 4.7 fixed most of the major problems, that is not the case. Every day I find bugs, and other issues in my own code and in the code of others. At this time, Qt 4.7 is still in beta on Snow Leopard. I haven’t heard when the final version will be released, but I can only hope it is soon.

For that reason, it is possible (perhaps even probable) that you’re not doing anything wrong. Your problem might just be that, for whatever reason, PyQt is unable to correctly configure and install on your system. If you really need your program to work, I would recommend that you download Virtual Box and install a Linux Virtual machine. For most of the open source/scientific programs I need, this has been much easier than trying to troubleshoot PyQt and the bizarre python distribution included with Mac OS X.

As to your problem, sipconfig.py should be installed when you configure and install sip. After you configure (“python configure.py …”) and compile (“make”), make sure that you run the install command (“sudo make install”). This must be run as the root user (the “sudo” bit), or it will not work correctly. You’ll get an error that says, “Insufficient permissions”, or something like that.

First, I would try and reconfigure/install sip. If that doesn’t solve the problem, I’m not sure what to recommend. The error that you are getting is a linker error (not a compiler error), which means that it can’t find an appropriate library (like sip) to which it can link. Given the frequency that Apple rearranges the internals of their operating system, linker errors crop up with alarming regularity.

One last thought, is there a particular Qt module that fails? I’ve occasionally had this problem when trying to link against Qt Webkit. This article was written prior to the introduction of Safari 5, which may be causing trouble. (I don’t know, I haven’t tried to compile PyQt since writing this article.)

In summary, PyQt on OS X is very hit/miss. If you need it to work reliably, either use Windows or Linux. This is easy to do via Bootcamp, VMware/Parallels or Virtual Box; and is probably your best bet. While things will run slightly slower, it is worth not having to deal with the installation headaches.

To install PyQt on Linux is one simple command:

sudo apt-get install pyqt

Sorry, I couldn’t be of more help.

Cheers,

Rob

Rob Oakes wrote a comment on July 7, 2010

@Yarko: Sorry, but I’m not sure what to recommend. You might try deleting the referenced tmp directory, and then removing qmake from your path. (Alternatively, there is an uninstall script for Qt in the /Developer/ directory.) I’d also clean out /opt/, where custom built versions of Qt tend to be installed.

From there, try installing the Qt 4.7 beta version. As I mention in the previous comment, Qt on Mac is a mess. PyQt is even worse. I wish Nokia would hurry up and fix it, and that Apple would take backwards compatibility seriously. (In both cases, I’m not holding my breath.)

The only real recommendation I can make is: if you are trying to set up a production environment, consider using Linux. It’s easier to install/configure, and is far easier to keep current.

Rob Oakes wrote a comment on July 8, 2010

As a follow-up to my comments yesterday, I spent a bit of time this morning with the newest version of Qt 4.7 (Beta 2, July 8, 2010). I was able to compile all of the modules (against the most recent snapshots of SIP and PyQt) and to install. Since Beta 1 (the version used in the article), there have been a number of improvements and bugfixes. Buttons no longer stick, and issues with pipes appear to have been repaired. I am, therefore, cautiously optimistic that PyQt might be usable again on Mac OS X.

Edit: Nevermind, I spoke much too soon. After pushing a few more buttons and trying to use my backup program (Time Drive), PyQt still appears to be horribly broken. Backup failed unexpectedly with cryptic errors. Moreover, when compiling LyX-Outline against 4.7, I still still see the bizarre disappearing Window bug. It appears that PyQt/Qt 4.7 are still not ready for primetime on Mac.

Viktor Ferenczi wrote a comment on August 23, 2010

First of all, thanks for the nice tutorial!

Compiling and installing sip worked fine, but configuring PyQt did not work, since it did not find the spiconfig module. It turned out that the library path in your article (/Library/Python/2.6/site-packages) is not on the module search path for my Python 2.6.5 installation (the DMG one from python.org).

I had to use the following library path (-d) in the configure command to overcome this: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages

So the configure lines which worked for me:

python2.6 configure.py -d /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages

I had to remove the sip module files form the original library location, then retry compiling both sip and PyQt with the configure line above to get both of them compiled and installed successfully.

I don’t know why the original (shorter) site-packages directory is missing from my default module search path, however. (I did not mix OS X’s own python and the one I installed (2.6.5) for sure.)

Viktor Ferenczi wrote a comment on August 23, 2010

Finally, I got the same linker error as Courtney did. I compiled sip-0.10.5 and PyQt 4.7.2 beta 2 on Python 2.6.5. The detailed error message is:

rm -f libpythonplugin.dylib
g++ -headerpad_max_install_names -single_module -dynamiclib -o libpythonplugin.dylib pluginloader.o moc_pluginloader.o -F/Library/Frameworks -L/Library/Frameworks -framework Python -L/tmp/qt-stuff-83153/source/qt-everywhere-opensource-src-4.7.0-beta2/lib -F/tmp/qt-stuff-83153/source/qt-everywhere-opensource-src-4.7.0-beta2/lib -framework QtDesigner -framework QtScript -framework QtXml -framework QtGui -framework QtCore
ld: warning: directory ‘/tmp/qt-stuff-83153/source/qt-everywhere-opensource-src-4.7.0-beta2/lib’ following -L not found
ld: warning: directory ‘/tmp/qt-stuff-83153/source/qt-everywhere-opensource-src-4.7.0-beta2/lib’ following -F not found
ld: warning: in /Library/Frameworks/Python.framework/Python, missing required architecture x86_64 in file
Undefined symbols:
“_Py_Initialize”, referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
“_PyLong_AsVoidPtr”, referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
“_PyErr_Print”, referenced from:
PyCustomWidgets::getModuleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::getModuleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
“_PyString_FromString”, referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
“_PyType_IsSubtype”, referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
“_PyModule_GetDict”, referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
“_PyObject_CallObject”, referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
“_PyObject_CallFunctionObjArgs”, referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
“_PyList_Append”, referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
“_Py_IsInitialized”, referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
“_PyDict_Next”, referenced from:
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
“_PyImport_ImportModule”, referenced from:
PyCustomWidgets::getModuleAttr(char const*, char const*)in pluginloader.o
PyCustomWidgets::PyCustomWidgets(QObject*)in pluginloader.o
“_PyObject_GetAttrString”, referenced from:
PyCustomWidgets::getModuleAttr(char const*, char const*)in pluginloader.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

According to what is returned by Python 2.6’s platform.architecture() function my platform is 32 bits, so something is wrong here with the compile target (e.g. the setting the right bit number of the target platform).

Viktor Ferenczi wrote a comment on August 23, 2010

Append this to the end of the above error message:

make[1]: *** [libpythonplugin.dylib] Error 1
make: *** [all] Error 2

Viktor Ferenczi wrote a comment on August 23, 2010

The post below seems to be related to the linker issue we faced here. Trying this solution, but by setting a 32 bit target architecture:

https://bugs.launchpad.net/bzr-mac-installers/+bug/529987/comments/9

Viktor Ferenczi wrote a comment on August 23, 2010

Got it compiled, finally.

Software versions:

– Python 2.6.5, DMG image downloaded from python.org
– Qt 4.7.0 beta 2, binary installer downloaded from Nokia
– sip 4.10.5
– PyQt Mac GPL 4.7.4

Configuration options used:

NOTE: The options are DIFFERENT for sip and PyQt!

sip:

python2.6 configure.py -d /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages –arch=i386

PyQt:

python2.6 configure.py -d /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages –use-arch=i386

I haven’t tried, but if you need to compile on a 64 bit platform, then you should replace i386 with x86_64, possibly. (Let me know if that worked for you, thanks.)

Rob Oakes wrote a comment on August 23, 2010

I can confirm that the x86_64 option works. I was able to compile and install the latest version of PyQt without errors, or linker troubles. I was also able to do so with the system version of Python. I know that there was some strangeness regarding whether Apple chooses to enable the 64 bit kernel, or not.

(I called a friend who might be described as a Mac Guru.)

Based on your type of machine, you may need to modify the compiler flag (–use-arch). Unfortunately, I do not have access to other types of machines to test different options.

Thanks, Viktor, for supplying these instructions.

Viktor Ferenczi wrote a comment on August 31, 2010

I had to start from scratch. I reinstalled Mac OS-X and installed everything again. This time the -d parameter was not needed to configure sip and PyQt correctly. The –arch and –use-arch parameters were still required, however.

Software versions for later reference:

Python:

Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin

XCode: 3.2.3 with SDK 4.0.2

sip 4.10.5

Qt 4.7.0 rc1

PyQt 4.7.4

Matt wrote a comment on September 10, 2010

Hi Viktor and all,

Could you please tell me which package you downloaded from Qt? Was it the SDK (995MB) or binaries (202MB)? I want to install as x86_64 but can’t seem to find out which package is x86_64 (both, neither…not sure)

Thanks,

Matt

Martin Rolfs wrote a comment on October 30, 2010

Hi all,

I found this site because I am having the same trouble that Courtney and Viktor describe. I wanted to install eric and so PyQt and sip are necessary dependencies. The instructions above helped a lot, however, so far they did not work for me. I used the following versions of the components:

Python 2.6.5 (installed using the Enthought package EPD-6.2.2 32-BIT MACOSX10.5+)
Qt
sip-4.12
PyQt4.8.1
Qt 4.7.0

After having failed several times trying to install the components in various orders and versions, I followed Rob’s instructions above. To be sure, I used the i386 flag for the configuration of both sip and PyQt. Still, I had the same error message that was described by Courtney and Viktor.

Then I tried providing the arguments that Viktor posted, however, using the appropriate paths on my system, i.e., I used

sip:
python configure.py -d /Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/ –arch=i386

PyQt:
python configure.py -d /Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/ –use-arch=i386

Only partial success. I got rid of the error messages, but for some reason, I still get an error message when I try to install eric, saying that PyQt is not installed:

Checking dependencies
Python Version: 2.6.5
Sorry, please install PyQt4.
Error: dlopen(/Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/PyQt4/QtCore.so, 2): Symbol not found: _sipQtConnect
Referenced from: /Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/PyQt4/QtCore.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/6.2/lib/python2.6/site-packages/PyQt4/QtCore.so

So far this has been the most helpful resource I could find. Thank you very much for sharing. But are there any updates on the issue that you are aware of? Any light at the end of the tunnel that future versions will resolve these hassles (I spend 2 nights already trying to install already)?

Thanks,
Martin

Richard Smith wrote a comment on January 24, 2011

Just wanted to say thanks for this clear tutorial. The whole process looked quite daunting until I came across your instructions – the whole thing went off without a hitch (I did guess that I could just replace 2.6 with 2.7 in the configure path – I was right!).

Olivier wrote a comment on March 15, 2011

Hi,
For some reasons, I tried with the arch flags, and that did not work for me, which by the way, I had to modify, because they were not accepted by my system. I still got the same errors as Viktor Ferenczi in his first post above.

I am using the Enthought Pyhton Distribution (EPD64), http://www.enthought.com/
I got it to work by 1) removing all 32-bit EPD and 2) booting Mac OS X 10.6.6 in 64-bit mode (see below).

That worked fine.

Best,

Olivier.

To boot in 64-bit kernel by default:

http://support.apple.com/kb/ht3773

To select the 64-bit kernel for the current startup disk, use the following command in Terminal:

sudo systemsetup -setkernelbootarchitecture x86_64

Then reboot.

To select the 32-bit kernel for the current startup disk, use the following command in Terminal:

sudo systemsetup -setkernelbootarchitecture i386

Note: This setting is stored in the /Library/Preferences/SystemConfiguration/com.apple.Boot.plist file and will take effect every time you start up from this disk.
You have first to make sure your system can be switch to 64-bit mode, read the links to the apple site above.

Carlos Garcia wrote a comment on May 22, 2011

Greetings everyone and thanks in advanced

Well I am working in a project that uses PyQt (64-bit) and requires python 2.6.6, the problem is that Python 2.6.6 dmg available here: http://www.python.org, is 32-bit (I need the stock version because there is a problem with mac ports and the process module), so I built a 64-bit version of python 2.6.6. My current problem is that python can not find pyqt, Is there a way to bind PyQt and the built python , maybe with configure.py and some parameters?

Rheinhard wrote a comment on June 19, 2011

Hi! I’m attempting to install PyQt on a newly purchased iMac (3.06 GHz Intel Core i3, running OS 10.6.7) I hit one bug in the process though which I should point out…

When attempting to do the configure.py step for PyQt4.7.3, I got the error displayed in this question:

http://stackoverflow.com/questions/2583092/how-to-install-pyqt-on-mac-os-x-10-6

The fix is contained in this answer:

http://stackoverflow.com/questions/2583092/how-to-install-pyqt-on-mac-os-x-10-6/3949646#3949646

Basically the process proceeded until it invoked SIP and I got the following error:

Generating the C++ source for the QtCore module…
sip: Usage: sip [-h] [-V] [-a file] [-b file] [-c dir] [-d file] [-e] [-g] [-I dir] [-j #] [-k] [-m file] [-o] [-p module] [-r] [-s suffix] [-t tag] [-w] [-x feature] [-z file] [file]
Error: Unable to create the C++ code.

Turns out that you CANNOT have any spaces in the file name or path to the folder which you are doing this process! Not even in any of the enclosing folders; so a full path such as:

~/Desktop/PyQt files/PyQt-mac-gpl-4.8.4

will fail, but changing the middle folder to:

~/Desktop/PyQt_files/PyQt-mac-gpl-4.8.4

will make it work!

Matt wrote a comment on November 22, 2011

Just a note, if you have the error that says:

Traceback (most recent call last):
File “configure.py”, line 37, in
import sipconfig
ImportError: No module named sipconfig

Then what I did to get it to build was take the sipconfig.py and .pyc file and paste them in the dir where my PyQt4 files are then run the script. That’s when it worked for me.

Ali wrote a comment on November 10, 2012

Hi,
To install SIP and PyQt on MacOSX you do not need to pass the -d argument for the configure, as this article does. You just download and untar the two folders, go into each and run 1) python configure.py 2) make 3) sudo make install, both times making sure you run from the two folders.

Care to comment?