Install PyQt4, Qt 4.7 on Mac OSX Lion

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

1) Download All the Required Software:

* Qt 4.7.4 Library: 
http://get.qt.nokia.com/qt/source/qt-mac-opensource-4.7.4.dmg

* SIP 4.13:
http://www.riverbankcomputing.co.uk/static/Downloads/sip4/sip-4.13.tar.gz

* PyQt 4.6.8:
http://www.riverbankcomputing.co.uk/static/Downloads/PyQt4/PyQt-mac-gpl-4.8.6.tar.gz

2) Install Qt 4.7

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

3) Install SIP

  • Unzip SIP 4.13, and from terminal, cd into the folder like:
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

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

open this file by using any editor, like vim.

find the line:

#  if !defined(MAC_OS_X_VERSION_10_6)
#       define MAC_OS_X_VERSION_10_6 MAC_OS_X_VERSION_10_5 + 1
#  endif

add

#  if !defined(MAC_OS_X_VERSION_10_7)
#       define MAC_OS_X_VERSION_10_7 MAC_OS_X_VERSION_10_6 + 1
#  endif

Then change

if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_6)

Into

if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_7)

Save and close the file.

4) Install PyQt

  • Unzip PyQt into a folder, and cd to that folder, like what we do 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 all turns out to be successful, you will a folder named PyQt4 under /Library/Python/2.7/site-packages/

To test if you can use it, in python prompt type

import PyQt4

to see if it can be load

Good Luck!

About these ads

12 comments

  1. JFG

    Really nice tutorial, thank you!

    Quick note, Qt 4.8 is out and officially supports Lion so step 4 can now be skipped.

    Cheers!

  2. CMon

    On OSXLion, when I enter :
    # python configure.py -q /Users/labo/Documents/QtSDK/Desktop/Qt/4.8.1/gcc/bin/qmake -d /Library/Python/2.7/site-packages/ -g –use-arch i386 –verbose
    I have this and I don’t have any idea to solve it :
    Determining the layout of your Qt installation…
    /Users/labo/Documents/QtSDK/Desktop/Qt/4.8.1/gcc/bin/qmake -spec macx-g++ -o qtdirs.mk qtdirs.pro
    make -f qtdirs.mk
    g++ -c -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -arch i386 -Wall -W -DQT_CORE_LIB -DQT_SHARED -I/Users/labo/Documents/QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/macx-g++ -I. -I/Users/labo/Documents/QtSDK/Desktop/Qt/4.8.1/gcc/lib/QtCore.framework/Versions/4/Headers -I/Users/labo/Documents/QtSDK/Desktop/Qt/4.8.1/gcc/include/QtCore -I/Users/labo/Documents/QtSDK/Desktop/Qt/4.8.1/gcc/include -I. -F/Users/labo/Documents/QtSDK/Desktop/Qt/4.8.1/gcc/lib -o qtdirs.o qtdirs.cpp
    g++ -headerpad_max_install_names -arch x86_64 -arch i386 -Xarch_x86_64 -mmacosx-version-min=10.5 -o qtdirs.app/Contents/MacOS/qtdirs qtdirs.o -F/Users/labo/Documents/QtSDK/Desktop/Qt/4.8.1/gcc/lib -L/Users/labo/Documents/QtSDK/Desktop/Qt/4.8.1/gcc/lib -framework QtCore -L/usr/local/pgsql/lib -L/tmp/qt-stuff-85167/source/qt-everywhere-opensource-src-4.8.1/Desktop/Qt/4.8.1/gcc/lib
    ld: warning: directory not found for option ‘-L/usr/local/pgsql/lib’
    ld: warning: directory not found for option ‘-L/tmp/qt-stuff-85167/source/qt-everywhere-opensource-src-4.8.1/Desktop/Qt/4.8.1/gcc/lib’
    ld: warning: directory not found for option ‘-L/usr/local/pgsql/lib’
    ld: warning: directory not found for option ‘-L/tmp/qt-stuff-85167/source/qt-everywhere-opensource-src-4.8.1/Desktop/Qt/4.8.1/gcc/lib’
    ld: warning: ignoring file /Users/labo/Documents/QtSDK/Desktop/Qt/4.8.1/gcc/lib/QtCore.framework/QtCore, file was built for unsupported file format which is not the architecture being linked (i386)
    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//ccINEwnJ.out (No such file or directory)
    make: *** [qtdirs.app/Contents/MacOS/qtdirs] Error 1
    Error: Failed to determine the layout of your Qt installation. Try again using
    the –verbose flag to see more detail about the problem.

  3. kespindler

    These instructions were SUPER helpful. Thank you!! I installed on Lion with Python3 (3.2.2, specifically). I managed to accomplish it without a few of the flags you set. No configure flags, no manually editing header files. Just used the same workflow, and it all worked fine. Thanks again!

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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