Last Update Aug/13/2012: check out PyQtX, nice and easy one stop installation app. Thanks AbiusX!

I’ve been searching for the ways to successfully install PyQt4 on my Macbook Pro with Lion 10.7.2.

After a long hard test, here comes my final working steps:

1) Download All the Required Software

2) Install Qt 4.7

This is pretty straightforward. Double click it and install it like a normal dmg file. It will be installed under /Developer/Applications/Qt

3) Install SIP

  • Unzip SIP 4.13, then from terminal, cd into the folder:
cd ~/Downloads/sip
  • Then type:
python configure.py

After that, it will install to your current version of python. ( in my mac, I only have 2.7)

If you want to specify which python to use, you can type:

python configure.py -d /Library/Python/2.7/site-packages --arch x86_64
  • Make and install it:
make

sudo make install

4) Change some code in Qt

Since Qt 4.7 does not officially support Lion, you might get error like: “This version of Mac OS X is unsupported”, if you are not going to use some of its features in Lion, Qt will work pretty well. In order to get rigid of this annoying error, you need to make some changes to the header file named: qglobal.h, which lies in /Library/Frameworks/QtCore.framework/Versions/4/Headers

  • Open qglobal.h by using any editor, like vim.

  • Find the following line:

#  if !defined(MAC_OS_X_VERSION_10_6)
#       define MAC_OS_X_VERSION_10_6 MAC_OS_X_VERSION_10_5 + 1
#  endif
  • And add the following line of code
#  if !defined(MAC_OS_X_VERSION_10_7)
#       define MAC_OS_X_VERSION_10_7 MAC_OS_X_VERSION_10_6 + 1
#  endif
  • Then find this line
if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6)
  • And change it to
if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_7)

Save and close the file.

5) Install PyQt

  • Unzip PyQt into a folder, and cd into that folder, like what we just did for install SIP
  • Inside PyQt’s folder, type
python configure.py -d /Library/Python/2.7/site-packages/ -g --use-arch x86_64
  • After that, type
make
  • It takes about 10 mins to finish, then type
make install

If everything goes well, you should find a folder named PyQt4 under /Library/Python/2.7/site-packages/

To test if you have successfully installed it, go to python prompt and type

import PyQt4

and then see if it can be loaded without errors.

Good Luck!