Skip to content

How to Install PyQt4 on OS X

Note : this is a tutorial on Mac OS X 10.6.4, with : PyQt-mac-gpl-snapshot-4.7.5-8a6793a155e0.tar.gz and with : sip-4.11-snapshot-052b642f04a8.tar.gz.
It should be the same on previous and next versions. ( if you have some bugs you may also contact me )

How to install PyQt4 ?

  1. Download the SIP package (snapshot for OS x )
  2. Download the PyQt package (snapshot for OS x)
  3. Download Qt
  4. Install Qt
  5. Install SIP
  6. Install PyQt
  7. and try !

Let’s download the Qt binary from the website : Download site (You may take the complete SDK)

Let’s download the SIP snapshot : Download site (for OS x)

Let’s download the PyQt snapshot : Download site (for OS x)

And now let’s install the first Qt binary, just follow and click on next until it as finished to install.

SIP :

SIP is the program that bind C++ with Python

let’s  go were you have downloaded the sip tar.gz and enter the folder

and we are gonna try to install it with the following lines :

– arch i386 is to specify that we want this architecture

then lets make it and install it with the following commands :

PyQt4:

Once installed let’s move back an go to the PyQt folder to configure it and install it with the following command :

and let’s try to configure it with the right things

then let’s make them with:

and now, everything should be Up and running.

 

In OS X Lion and with the new versions there is a thread on QT website https://bugreports.qt.nokia.com/browse/QTCREATORBUG-6222 which says that qmake-4.7 is hidden in /usr/bin. Could someone confirm that it works.

EDIT 2013 :

Many of you happen to have problems installing PyQT and ask me questions about the installation process and errors, via e-mails, or in the comment section, please note that I can’t answer all of them, although, if you find a fix to your problem, please  let me know, or add a comment with the fix !  You are probably not the only one with the problem. 

Randall Munroe : xkcd: Wisdom of the Ancients

Randall Munroe : xkcd: Wisdom of the Ancients

Edit 09/13 : 

If you previously encountered the following issue :

It might have been because the versions in this tutorial had not been updated, however, thanks to Rick’s comment the changes have now been made. The versions in the post are now Python 2.7, Qmake 4.8 and the architecture was changed from ‘i386 to x86_64′.

 

Edit 01/14 :

If the above didn’t worked for you or if you want a simpler way to install PyQT4 / 5 on OS X  you can use homebrew.  Once brew installed, simply type the following commands in your terminal :

And that should work for you as well.

{ 49 } Comments

  1. QT98 | 8 May 2011 at 22 h 54 min | Permalink

    Thanks a lot. Finally working !!!

  2. Noktec | 12 May 2011 at 18 h 38 min | Permalink

    You’r welcome ;)

  3. me | 29 May 2011 at 12 h 59 min | Permalink

    Your list of commands were a HUGE timesaver and it all worked. THANKS!!!

  4. Noktec | 29 May 2011 at 17 h 46 min | Permalink

    Thanks man ;)

  5. Ecker | 24 July 2011 at 2 h 12 min | Permalink

    I get to the first “make” command.
    Which just returns “command not found”.

    If I skip it and continue all I get on the next step is “ImportError: No moudle named sipconfig”

    What did I miss? I tried, and tried again.

  6. Ecker | 24 July 2011 at 2 h 44 min | Permalink

    I found out that X Code have to be installed for the “Make” command to work.

  7. Noktec | 24 July 2011 at 14 h 33 min | Permalink

    Yes, Xcode needed to be installed ( in theory everything should work well, on Leopard or Snow Leopard but i didn’t tried yet on Lion)

  8. Guillermo | 31 July 2011 at 18 h 52 min | Permalink

    Muchas gracias! this worked wonders i got it with qmake 4.7 just fine.

  9. yui | 17 August 2011 at 9 h 50 min | Permalink

    Hi, I am installing PyQt4 into my MacBookPro (10.6, unibody, core 2 duo, 2009).
    After I launched “$ python configure.py –use-arch=x86_64″,
    It’s been already almost 3 hours..
    Do you think Is it normal it takes so long time??

  10. Noktec | 17 August 2011 at 10 h 59 min | Permalink

    Hi,

    Actually I just read that it could take around 3h to 3h30′
    so you should let it run :) and see later on, if it gives
    any error message.

  11. yui | 17 August 2011 at 15 h 25 min | Permalink

    Thanks a lot for your reply.
    unfortunately it had been running for 6 hours so I just did force quite :(

    Apart from that, in this website, we are supposed to use Python 2.6, aren’t we?
    I am using 2.7, not 2.6, so in that case should I simply put a command something like following??:
    python configure.py -d /Library/Python/2.7/site-packages –arch x86_64

    Sorry for such a very very stupid question.
    I am a beginner for Python (and even for general programming).
    (Now I am trying to build an environment “Spyder2″ for Python2.7 in my Mac.)

  12. SSF | 10 January 2012 at 18 h 05 min | Permalink

    It is not working on the lion, the path /usr/bin/qmake-4.6 is not created after installing the SIP.

  13. Noktec | 13 January 2012 at 3 h 20 min | Permalink

    Dear SSF for your problem, I found a solution -> https://bugreports.qt.nokia.com/browse/QTCREATORBUG-6222

    tell me if this helped

  14. Jason Viloria | 16 January 2012 at 0 h 01 min | Permalink

    I needed to work with python2.7 due to collaboration with other people working on linux using python2.7 and this is what I did.

    1. Install macports and installed python2-7
    2. downloaded and installed the latest QT SDK. it installed it in QtSDK in my home folder /Users/jnvilo/QtSDK
    3. I downloaded the latest SIP version from the site provided and simply did /opt/local/bin/python2.7 configure.py; make ; make install
    4. When i tried to do the same with PyQt it complained about qt being static and I had to run the following command instead:

    python configure.py -q /Users/jnvilo/QtSDK/Desktop/Qt/474/gcc/bin/qmake -g

    I hope this helps
    /jnvilo

  15. Jason Viloria | 16 January 2012 at 0 h 02 min | Permalink

    Oh and last command should be:

    /opt/local/bin/python2.7 configure.py -q /Users/jnvilo/QtSDK/Desktop/Qt/474/gcc/bin/qmake -g

  16. Noktec | 16 January 2012 at 1 h 11 min | Permalink

    Thanks for the tips Jason !

  17. chair rail | 20 January 2012 at 20 h 02 min | Permalink

    I don’t know why…

  18. CMon | 25 April 2012 at 13 h 46 min | Permalink

    I have installed sip-4.13.2 on python 2.7 (on my Mac OSX 10.7.3 Lion). I don’t have errors when I do $ python and then >>import sip or >>import sipconfig.

    I have installed qt-mac-opensource-4.8.1.dmg and QtSdk-online-mac-x86-v1.2.1.dmg, but when I enter :
    $python configure.py -q /usr/bin/qmake-4.8 -d /Library/Python/2.7/site-packages/ –use-arch i386
    I have this error message that I cannot solve by myself :
    Determining the layout of your Qt installation…
    Error: Failed to determine the layout of your Qt installation. Try again using
    the –verbose flag to see more detail about the problem.
    How to solve this ? Or how to have more informations on this problem ?

  19. Noktec | 25 April 2012 at 13 h 55 min | Permalink

    Using the full QT path. I just saw that example

    “python configure.py -q /home/mahmoud/qtsdk-2009.05/qt/bin/qmake”

    So, try the full path to qmake.

    See this : http://ubuntuforums.org/archive/index.php/t-1427945.html

  20. CMon | 25 April 2012 at 14 h 14 min | Permalink

    Well in the QtDSK installation I don’t have /qt/bin/qmake things but I have in the qmake command in /usr/bin/qmake (and also a qmake-4.8)…

  21. Noktec | 25 April 2012 at 14 h 34 min | Permalink

    Btw Have you looked at this http://www.noktec.be/python/how-to-install-pyqt4-on-osx#comment-690 ?
    look at the path used.

  22. CMon | 25 April 2012 at 16 h 23 min | Permalink

    No changes with :
    $python configure.py -q /Users/labo/Documents/QtSDK/Desktop/Qt/4.8.1/gcc/bin/qmake -d /Library/Python/2.7/site-packages/ –use-arch i386 –verbose

  23. Noktec | 26 April 2012 at 13 h 40 min | Permalink

    I’m sorry I have no more ideas, but if you find the answer could you please tell me so I’ll be able to help similar problems in the future.

  24. AbiusX | 8 July 2012 at 3 h 27 min | Permalink

    You don’t need to go through all the hassle, the PyQtX binaries now provide you everything ready to use!

  25. Noktec | 8 July 2012 at 12 h 18 min | Permalink

    Hey AbiusX,

    I haven’t used PyQTX yet, but I’ll give it a try, and then I’ll edit my post following your comment.

    Btw thank you for the head up.

  26. Michael | 13 August 2012 at 20 h 25 min | Permalink

    if you get this error msg:
    configure.py: error: ‘/usr/bin/qmake-4.6′ is not a file

    check if this file exists in /usr/bin.
    if it doesn’t, install Qt libraries from:
    http://qt.nokia.com/downloads

  27. Juan | 28 February 2013 at 22 h 57 min | Permalink

    Hi, I’ve followed your instructions to the letter, but I still can’t install PyQt for Mountain Lion. The only way I can get something done is this:

    1. Download and Install Qt 5.0.1 (installs in local directory)

    2. Compile Sip 4.14 (all good here)

    3. Compile PyQt 4.9.6 with flag -q /Users/Juan/Qt5.0.1/clang_64/bin/qmake (there is no qmake in /usr/bin and /usr/local/bin or /usr/local/Cellar/qt/4.8.4/bin/ throws the following error:

    Determining the layout of your Qt installation…
    Error: Failed to determine the layout of your Qt installation. Try again using
    the –verbose flag to see more detail about the problem.

    4. Last step: make, but it does not go all the way through, it stops and throws the following error:

    /Users/Juan/Downloads/PyQt-mac-gpl-4.9.6/sip/QtCore/qstring.sip:205:35: error:
    use of undeclared identifier ‘TRUE’
    static bool check_codec = TRUE;
    ^
    /Users/Juan/Downloads/PyQt-mac-gpl-4.9.6/sip/QtCore/qstring.sip:213:27: error:
    use of undeclared identifier ‘FALSE’
    check_codec = FALSE;
    ^
    2 errors generated.
    make[1]: *** [sipQtCoreQString_0.o] Error 1
    make: *** [all] Error 2

    Any ideas? Help is appreciated!

    PS: I also tried with home-brew… but did not work neither.

  28. Noktec | 28 February 2013 at 23 h 12 min | Permalink

    Hi,

    I’ll try to install it on my Mac tonight or tomorrow, I let you (in the comments) know if I encounter the same problems and if I found any solutions.

  29. Gerardo | 8 June 2013 at 0 h 24 min | Permalink

    Was anyone able to install PyQt on Mountain Lion?
    My Qt 4.8 installation goes through fine, so does SIP.
    qmake is in /usr/bin (among other locations)

    Still, when compiling PyQt I get this erro:

    python ./configure.py –confirm-license -e QtCore -e QtGui -e QtOpenGL -q /usr/bin/qmake –use-arch x86_64
    Determining the layout of your Qt installation…
    Error: Failed to determine the layout of your Qt installation.

    Turning –verbose on yields:

    python ./configure.py –confirm-license -e QtCore -e QtGui -e QtOpenGL -q /usr/bin/qmake –use-arch x86_64 –verbose
    Determining the layout of your Qt installation…
    /usr/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 -Wall -W -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Qt4.8/mkspecs/macx-g++ -I. -I/Library/Frameworks/QtCore.framework/Versions/4/Headers -I/usr/include/QtCore -I/usr/include -I. -F/Library/Frameworks -o qtdirs.o qtdirs.cpp
    In file included from /Library/Frameworks/QtCore.framework/Versions/4/Headers/QCoreApplication:1,
    from qtdirs.cpp:1:
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:45:28: error: QtCore/qobject.h: No such file or directory
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:46:31: error: QtCore/qcoreevent.h: No such file or directory
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:47:31: error: QtCore/qeventloop.h: No such file or directory
    In file included from /Library/Frameworks/QtCore.framework/Versions/4/Headers/QFile:1,
    from qtdirs.cpp:2:
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qfile.h:45:30: error: QtCore/qiodevice.h: No such file or directory
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qfile.h:46:28: error: QtCore/qstring.h: No such file or directory
    In file included from /Library/Frameworks/QtCore.framework/Versions/4/Headers/QLibraryInfo:1,
    from qtdirs.cpp:3:
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qlibraryinfo.h:46:24: error: QtCore/QDate: No such file or directory
    In file included from /Library/Frameworks/QtCore.framework/Versions/4/Headers/QTextStream:1,
    from qtdirs.cpp:4:
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qtextstream.h:47:26: error: QtCore/qchar.h: No such file or directory
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qtextstream.h:48:28: error: QtCore/qlocale.h: No such file or directory
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qtextstream.h:49:35: error: QtCore/qscopedpointer.h: No such file or directory
    In file included from /Library/Frameworks/QtCore.framework/Versions/4/Headers/QCoreApplication:1,
    from qtdirs.cpp:1:
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:57: error: ‘QT_BEGIN_HEADER’ does not name a type
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:71: error: function definition does not declare parameters
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:230: error: ‘QCoreApplication’ has not been declared
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:230: error: ‘sendEvent’ declared as an ‘inline’ variable
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:230: error: ‘QObject’ was not declared in this scope
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:230: error: ‘receiver’ was not declared in this scope
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:230: error: ‘QEvent’ was not declared in this scope
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:230: error: ‘event’ was not declared in this scope
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:230: error: initializer expression list treated as compound expression
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:231: error: expected ‘,’ or ‘;’ before ‘{’ token
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:233: error: ‘QCoreApplication’ has not been declared
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:233: error: ‘sendSpontaneousEvent’ declared as an ‘inline’ variable
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:233: error: ‘QObject’ was not declared in this scope
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:233: error: ‘receiver’ was not declared in this scope
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:233: error: ‘QEvent’ was not declared in this scope
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:233: error: ‘event’ was not declared in this scope
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:233: error: initializer expression list treated as compound expression
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:234: error: expected ‘,’ or ‘;’ before ‘{’ token
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:236: error: ‘QCoreApplication’ has not been declared
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h: In function ‘void sendPostedEvents()’:
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:236: error: too many arguments to function ‘void sendPostedEvents()’
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:236: error: at this point in file
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h: At global scope:
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:284: error: two or more data types in declaration of ‘qAddPostRoutine’
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:285: error: two or more data types in declaration of ‘qRemovePostRoutine’
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:286: error: expected initializer before ‘qAppName’
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qcoreapplication.h:293: error: ‘QT_END_NAMESPACE’ does not name a type
    In file included from /Library/Frameworks/QtCore.framework/Versions/4/Headers/QFile:1,
    from qtdirs.cpp:2:
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qfile.h:56: error: ‘QT_BEGIN_HEADER’ does not name a type
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qfile.h:65: error: function definition does not declare parameters
    /Library/Frameworks/QtCore.framework/Versions/4/Headers/qfile.h:212: error: expected constructor, destructor, or type conversion before ‘(’ token
    make: *** [qtdirs.o] Error 1

  30. Noktec | 8 June 2013 at 17 h 39 min | Permalink

    I personally have never encountered that problem, although by searching on google I found someone on gentoo having the same problem, you might want to check it.

  31. Tj Singh | 11 July 2013 at 16 h 19 min | Permalink

    hi

    I’m having the current problem when installing PyQt 4.10.3:

    make:

    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make[1]: *** [libpyqt4.dylib] Error 1
    make: *** [all] Error 2
    sh-3.2#

    sudo make install:

    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make[1]: *** [libpyqt4.dylib] Error 1
    make: *** [install] Error 2
    sh-3.2#

    Steps taken: I followed your instructions up to make and sudo make install and the above are the error messages I receive. Before hand however I had to run the

    1 python configure-ng.py

    before running:

    1 python configure.py -q /usr/bin/qmake-4.6 -d /Library/Python/2.7/site-packages/ –use-arch=x86_64

    This is because I was having the same error as CMon when it was determining the Qt layout, however that issue passed once I ran the python configure-ng.py and the rest is history.

    Any ideas?

    Thanks

    Tj

  32. Noktec | 3 August 2013 at 16 h 06 min | Permalink

    Well, I’m sorry, I have not been installing PyQT4 lately, however if you found the solution, please, provide it.

  33. Dr Coon | 16 September 2013 at 20 h 42 min | Permalink

    Hi, this whole thing is a very big shit. Does not work of course. Unable to compile, hundreds
    of mysterious error messages, just like all the similar kludges where there is not a compact solution install this install that, compile this, compile that. Disgusting.

  34. Noktec | 16 September 2013 at 20 h 54 min | Permalink

    Well, I’m glad you liked the blog post “Dr. Coon”. Too bad if you cant follow simple instructions !

  35. Annis | 22 September 2013 at 3 h 48 min | Permalink

    Thanks, Keep up the good work.

  36. Rick G | 27 September 2013 at 4 h 20 min | Permalink

    On OS X 10.8.5 I also encountered the “Error: Failed to determine the layout of your Qt installation” issue. I solved it by changing i386 to x86_64 everywhere. I also used qmake-4.8 and python 2.7. So my total workflow was the same with the following replacements:

    4.6 -> 4.8
    2.6 -> 2.7
    i386 -> x86_64

    You might consider updating the main blog post to reflect this, since these are probably more common build conditions going forward. Thanks for your helpful post.

  37. Noktec | 27 September 2013 at 9 h 18 min | Permalink

    Thanks for the update Rick ! I’ll modify the post right now !

  38. Paolo | 6 October 2013 at 2 h 54 min | Permalink

    Thanks for your Code!

  39. Cupitor | 24 October 2013 at 19 h 43 min | Permalink

    Just as a comment, In newer versions of PyQT you have to change your guide, to give options for the configure.py -d for destination and -q for the location of qmake!

  40. Noktec | 25 October 2013 at 0 h 01 min | Permalink

    Thanks Cupitor although, isn’t that what’s written on this line ?

    python configure.py -q /usr/bin/qmake-4.8 -d /Library/Python/2.7/site-packages/ --use-arch x86_64

  41. Steve | 26 December 2013 at 22 h 28 min | Permalink

    Mac homebrew on Mavericks

    brew install qt
    brew install sip
    brew install pyqt

    done.

  42. Karine | 20 January 2014 at 13 h 28 min | Permalink

    Thanks Steve, that really helped me!

  43. TN | 25 January 2014 at 7 h 41 min | Permalink

    awesome! Thanks a lot mate.

  44. lee | 28 January 2014 at 20 h 38 min | Permalink

    Thanks. It worked for me in Mavericks with qt5

  45. vijay | 8 April 2014 at 18 h 21 min | Permalink

    Thank you for the post. Very helpfull. However, had trouble with pyQt. Installing with homebrew. Once again, thanks a ton. VJ

  46. Ramas | 12 May 2014 at 11 h 58 min | Permalink

    Guys where can I get the homeBrew, the one I have got is ‘HomebrewInstaller_0102′ which doesn’t have a terminal to execute the commands… Thanks in advance

  47. Noktec | 12 May 2014 at 12 h 05 min | Permalink

    This is how you find something ! such as homebrew ! http://lmgtfy.com/?q=homebrew+mac

  48. André | 14 May 2014 at 6 h 34 min | Permalink

    I tried many times to install this, but today I found out that instead of using ” python configure.py -d /Library/Python/2.7/site-packages –arch x86_64″, just “python configure.py” worked and I thought i should let you know.

  49. Noktec | 21 May 2014 at 17 h 26 min | Permalink

    Thanks for the update

{ 2 } Trackbacks

  1. [...] 1-3 were adapted from here. Step 4 was adapted from here. Share this:TwitterFacebookLike this:LikeBe the first to like this [...]

  2. A Qt GUI for Python scripts « Thesis Journal | 29 August 2012 at 4 h 23 min | Permalink

    [...] To install PyQt on my system (OS X 10.6.8), with Xcode installed, download and install SIP and PyQt4 following these directions here. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *