How to install PyQt on Mac OS Snow Leopard

I’ve never been a fan of the Qt library (it might take a long post to explain the reasons, but I don’t have time to write). However, there are a few good programs I want to use which requires Qt library. Installing Qt library on Mac OS was not difficult, thanks to the effort by Nokia: you can download an installer for Mac OS on

Difficulty arose when I installed PyQt4, the Qt wrapper for Python, which is used by quite a few Python programs such as Spyder, Eric4, Leo. After installing SIP successfully, I tried to build PyQt4 and got an error at the linking phase. It took me several hours to figure what went wrong and how to fix the problems. The problem is that the Qt library is 32bit while, by default, python builds PyQt4 in 64bit. That caused problem when it tried to link 64bit object files with 32bit Qt library. To fix this issue, we need to force python to build PyQt4 in 32bit, and we also need to re-build SIP in 32bit mode. In fact, there exists a document on the PyQt website that explains how to build PyQt4 on Mac OS/Snow Leopard, but it is not in the README file in the source distribution. I will summarize the steps below:

  1. If you use the python version that comes with Mac OS (2.5 for Snow Leopard), make sure that it runs in 32bit mode by issuing the command
    defaults write Prefer-32-Bit -bool yes
    in the terminal. Alternatively, set the following environment variable:
  2. Re-build SIP in 32bit
    • Configure SIP to build in 32bit by the command:
      python --arch i386
    • Build and install SIP:
      sudo make install
  3. Build PyQt4 in 32bit
    • Configure PyQt4 to build in 32bit:
      python --use-arch i386
    • Build and install PyQt4:
      sudo make install
  4. If every step is successful, you should have PyQt4 built and installed. To test it, either run the provided examples or open a Python console and try: import PyQt4. It should not give any error.

Now, all Python programs that use PyQt4 should run fine.

This entry was posted in MacOS, Python and tagged , , . Bookmark the permalink.

8 Responses to How to install PyQt on Mac OS Snow Leopard

  1. Pingback: Install QScintilla2 (to install Eric4) on Mac OS Snow Leopard | Truong's Weblog

  2. Fred says:

    This is what I get when I configure PyQT:

    Generating the C++ source for the QtCore module…
    sh: /Users/apy/tmp/env27/bin/../bin/sip: No such file or directory
    Error: Unable to create the C++ code.

    Any suggestions? Many thanks,

  3. Fred says:

    Thanks Truong, re-did it and it works!

  4. Illia Z. says:

    every time I run the :python –use-arch i386 for PyQt it gives me this error

    Error: Make sure you have a working Qt v4 qmake on your PATH or use the -q
    argument to explicitly specify a working Qt v4 qmake.

    Any suggestions? Many thanks,
    Illia Z.

    • Just as the error message suggested: have you installed Qt4 for Mac? can you run qmake in the console? if yes, is it the version coming with Qt4? if no, you must either put it on your PATH environment variable or use -q followed by the explicit path to qmake.

  5. CMon says:

    On MacOsX Lion, if I enter : python -q /Users/labo/Documents/QtSDK/Desktop/Qt/4.8.1/gcc/bin/qmake -d /Library/Python/2.7/site-packages/ –use-arch i386 –verbose it failed complaining :
    Undefined symbols for architecture i386:
    “QTextStream::QTextStream(QIODevice*)”, referenced from:
    _main in qtdirs.o
    “QTextStream::~QTextStream()”, referenced from:
    _main in qtdirs.o
    “QTextStream::operator<<(char const*)", referenced from:
    _main in qtdirs.o
    "QTextStream::operator<<(QString const&)", referenced from:
    _main in qtdirs.o
    "QTextStream::operator<<(char)", referenced from:
    _main in qtdirs.o
    "QTextStream::operator<<(int)", referenced from:
    _main in qtdirs.o
    "QLibraryInfo::licensee()", referenced from:
    _main in qtdirs.o
    "QLibraryInfo::location(QLibraryInfo::LibraryLocation)", referenced from:
    _main in qtdirs.o
    "QCoreApplication::QCoreApplication(int&, char**, int)", referenced from:
    _main in qtdirs.o
    "QCoreApplication::~QCoreApplication()", referenced from:
    _main in qtdirs.o
    "QFile::open(QFlags)”, referenced from:
    _main in qtdirs.o
    “QFile::QFile(QString const&)”, referenced from:
    _main in qtdirs.o
    “QFile::~QFile()”, referenced from:
    _main in qtdirs.o
    “QString::fromAscii_helper(char const*, int)”, referenced from:
    QString::QString(char const*)in qtdirs.o
    “QString::free(QString::Data*)”, referenced from:
    QString::~QString()in qtdirs.o
    ld: symbol(s) not found for architecture i386
    collect2: ld returned 1 exit status
    lipo: can’t open input file: /var/tmp//ccGz7Yrt.out (No such file or directory)
    make: *** [] Error 1
    Error: Failed to determine the layout of your Qt installation.

    An idea of what’s wrong !

    • I don’t know much about Lion. Probably Apple dropped support for 32-bit architecture altogether, therefore you cannot build 32-bit binary anymore.

      This post is old. Probably QT now has 64-bit support and you don’t need to compile 32-bit.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s