Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A simple guide to install PyQt5 on Mac OS X 10.9 (Maverick) and use python 3.4 on a virtualenv.

Guide to install PyQt5 on Mac OS X with python 3.4 virtualenv

Description

A simple guide to install PyQt5 on Mac OS X 10.9 (Maverick) and use python 3.4 on a virtualenv.

Requirements

  • xcode 5.1.1
  • python 3.4.0
  • Qt libraries 5.2.1
  • SIP 4.15.5
  • PyQt 5.2.1

Download

installation

  • install xcode
  • install the Command Line Tools (open Xcode > Preferences > Downloads)
  • install Qt libraries (qt-opensource-mac-x64-clang-5.2.1.dmg)
  • install python 3.4
  • create a virtual env (i.e. ~/.env/ariane_mail)
  • unzip and compile SIP and PyQt
    cd /var/tmp
    cp /Users/gvincent/Downloads/PyQt-gpl-5.2.1.tar.gz .
    cp /Users/gvincent/Downloads/sip-4.15.5.tar.gz .
    tar xvf PyQt-gpl-5.2.1.tar.gz
    tar xvf sip-4.15.5.tar.gz
    cd sip-4.15.5/
    python3 configure.py -d ~/.env/ariane_mail/lib/python3.4/site-packages --arch x86_64
    make
    sudo make install
    sudo make clean
    cd ../PyQt-gpl-5.2.1/
    python3 configure.py --destdir ~/.env/ariane_mail/lib/python3.4/site-packages --qmake ~/Qt5.2.1/5.2.1/clang_64/bin/qmake
    make
    sudo make install
    sudo make clean
    ~/.env/ariane_mail/bin/python -c "import PyQt5"
@martinfinke

This comment has been minimized.

Show comment
Hide comment
@martinfinke

martinfinke Feb 12, 2015

Thanks for the guide! Works great. The only thing you didn't mention is: Before you run configure.py for PyQt, you have to workon ariane_mail. Otherwise, it will complain that SIP wasn't found (because it's not looking in the virtualenv).

Thanks for the guide! Works great. The only thing you didn't mention is: Before you run configure.py for PyQt, you have to workon ariane_mail. Otherwise, it will complain that SIP wasn't found (because it's not looking in the virtualenv).

@sandokandias

This comment has been minimized.

Show comment
Hide comment

big thks!

@s200999900

This comment has been minimized.

Show comment
Hide comment

Thanks!

@wucangji

This comment has been minimized.

Show comment
Hide comment
@wucangji

wucangji Apr 27, 2015

Thanks! better than the official website....

Thanks! better than the official website....

@nbro

This comment has been minimized.

Show comment
Hide comment
@nbro

nbro May 23, 2015

Please, specify better the reasong why you are using that code on the terminal. It is a bit difficult to guess why you are doing something or something else just from the code.

nbro commented May 23, 2015

Please, specify better the reasong why you are using that code on the terminal. It is a bit difficult to guess why you are doing something or something else just from the code.

@chasehd

This comment has been minimized.

Show comment
Hide comment
@chasehd

chasehd Jun 26, 2015

Also, if you've used workon and have you virtualenv activated (assuming the intention is just to have PyQt in your virtualenv), don't use sudo as it will attempt to install at /usr/local/lib instead of your virtualenv.

chasehd commented Jun 26, 2015

Also, if you've used workon and have you virtualenv activated (assuming the intention is just to have PyQt in your virtualenv), don't use sudo as it will attempt to install at /usr/local/lib instead of your virtualenv.

@hugeface

This comment has been minimized.

Show comment
Hide comment
@hugeface

hugeface Sep 15, 2015

"python3 configure.py --destdir ~/.env/ariane_mail/lib/python3.4/site-packages --qmake ~/Qt5.2.1/5.2.1/clang_64/bin/qmake" return "configure.py: error: '/Users/hugeface/Qt5.5/5.5/clang_64/bin/qmake' is not an executable"

"python3 configure.py --destdir ~/.env/ariane_mail/lib/python3.4/site-packages --qmake ~/Qt5.2.1/5.2.1/clang_64/bin/qmake" return "configure.py: error: '/Users/hugeface/Qt5.5/5.5/clang_64/bin/qmake' is not an executable"

@jsalzer1979

This comment has been minimized.

Show comment
Hide comment
@jsalzer1979

jsalzer1979 Sep 20, 2015

@hugeface watch your path... are you sure that you installed the EXACT same Qt libraries version? If you installed Qt5.5 the path on the example isn't going to work. Also are you using the same virtualenv as on the example or did you create your own? I didn't even follow the example for the virtualenv since I use my own naming convention and also ignored the path to qmake since my path is different.

@hugeface watch your path... are you sure that you installed the EXACT same Qt libraries version? If you installed Qt5.5 the path on the example isn't going to work. Also are you using the same virtualenv as on the example or did you create your own? I didn't even follow the example for the virtualenv since I use my own naming convention and also ignored the path to qmake since my path is different.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Oct 15, 2015

@hugeface go to '/Users/hugeface/Qt5.5/5.5/clang_64/bin/' and run 'chmod +x qmake'

ghost commented Oct 15, 2015

@hugeface go to '/Users/hugeface/Qt5.5/5.5/clang_64/bin/' and run 'chmod +x qmake'

@new-2-programming

This comment has been minimized.

Show comment
Hide comment
@new-2-programming

new-2-programming Oct 28, 2015

Error when running make in the PyQt-gpl folder:

/Users/Jon/Desktop/PyQt-gpl-5.5.1/sip/QtPositioning/qgeolocation.sip:28:10: fatal error: 'qgeolocation.h' file not found

Error when running make in the PyQt-gpl folder:

/Users/Jon/Desktop/PyQt-gpl-5.5.1/sip/QtPositioning/qgeolocation.sip:28:10: fatal error: 'qgeolocation.h' file not found

@forrestzhang

This comment has been minimized.

Show comment
Hide comment
@forrestzhang

forrestzhang Oct 30, 2015

PyQt-gpl-5.5/sip/QtPositioning/qgeolocation.sip:28:10: fatal error: 'qgeolocation.h' file not found

include <qgeolocation.h>

     ^

1 error generated.
make[1]: *** [sipQtPositioningcmodule.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [sub-QtPositioning-make_first-ordered] Error 2

PyQt-gpl-5.5/sip/QtPositioning/qgeolocation.sip:28:10: fatal error: 'qgeolocation.h' file not found

include <qgeolocation.h>

     ^

1 error generated.
make[1]: *** [sipQtPositioningcmodule.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [sub-QtPositioning-make_first-ordered] Error 2

@NeilGirdhar

This comment has been minimized.

Show comment
Hide comment

@new-2-programming @forrestzhang Try: -disable=QtPositioning

@new-2-programming

This comment has been minimized.

Show comment
Hide comment
@new-2-programming

new-2-programming Nov 4, 2015

Thanks sancholito, that link worked! One thing to note, I had to add that file in the link after running config in PyQt, otherwise it deleted the file.

Thanks sancholito, that link worked! One thing to note, I had to add that file in the link after running config in PyQt, otherwise it deleted the file.

@sancholito

This comment has been minimized.

Show comment
Hide comment
@sancholito

sancholito Nov 6, 2015

That's right, after the configure step the file has gone. Is there a way to keep it there, i.e. to tell configure.py to not clean it out?

That's right, after the configure step the file has gone. Is there a way to keep it there, i.e. to tell configure.py to not clean it out?

@ProfPh

This comment has been minimized.

Show comment
Hide comment
@ProfPh

ProfPh Dec 1, 2015

Everything pretty much installs fine and then I get this error when trying to import any Qt module in python (from pyqt5 import QtGui):

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyQt5/QtGui.so, 2): Library not loaded: @rpath/QtGui.framework/Versions/5/QtGui
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyQt5/QtGui.so
  Reason: image not found

I have reinstalled Qt and PyQt5 and I did have XCode installed and accepted

edit: Solution was to give up on trying to build it from source and get it from homebrew instead

ProfPh commented Dec 1, 2015

Everything pretty much installs fine and then I get this error when trying to import any Qt module in python (from pyqt5 import QtGui):

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyQt5/QtGui.so, 2): Library not loaded: @rpath/QtGui.framework/Versions/5/QtGui
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyQt5/QtGui.so
  Reason: image not found

I have reinstalled Qt and PyQt5 and I did have XCode installed and accepted

edit: Solution was to give up on trying to build it from source and get it from homebrew instead

@chiyuan-goh

This comment has been minimized.

Show comment
Hide comment
@chiyuan-goh

chiyuan-goh Dec 7, 2015

note that you might have to include --pyuic_interpreter to point to the right python executable if you are using virtualenv. pyuic5 doesn't work without this, in my setup.

note that you might have to include --pyuic_interpreter to point to the right python executable if you are using virtualenv. pyuic5 doesn't work without this, in my setup.

@hantsaniala

This comment has been minimized.

Show comment
Hide comment
@hantsaniala

hantsaniala Jan 15, 2016

How to fix it please?

Mac-mini:PyQt-gpl-5.2.1 Sir_001$ python3 configure.py --destdir ~/.env/Khadafi/lib/python3.4/site-packages/ --qmake ~/Qt5.2.1/5.2.1/clang_64/bin/qmake Querying qmake about your Qt installation... Determining the details of your Qt installation... Error: Failed to determine the detail of your Qt installation. Try again using the --verbose flag to see more detail about the problem.

How to fix it please?

Mac-mini:PyQt-gpl-5.2.1 Sir_001$ python3 configure.py --destdir ~/.env/Khadafi/lib/python3.4/site-packages/ --qmake ~/Qt5.2.1/5.2.1/clang_64/bin/qmake Querying qmake about your Qt installation... Determining the details of your Qt installation... Error: Failed to determine the detail of your Qt installation. Try again using the --verbose flag to see more detail about the problem.

@NathanDotTo

This comment has been minimized.

Show comment
Hide comment
@NathanDotTo

NathanDotTo Mar 19, 2016

Many thanks for this :-)

Many thanks for this :-)

@TPeterW

This comment has been minimized.

Show comment
Hide comment
@TPeterW

TPeterW Mar 20, 2016

I apparently am missing the QtWebKit and QtWebKitWidgest with the latest Qt5.6.0 and PyQt5.5.1, and I got the following error when I tried to run spyder

Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/spyderlib/spyder.py", line 3119, in main
mainwindow = run_spyder(app, options, args)
File "/usr/local/lib/python3.5/site-packages/spyderlib/spyder.py", line 3005, in run_spyder
main.setup()
File "/usr/local/lib/python3.5/site-packages/spyderlib/spyder.py", line 822, in setup
message=_("Spyder Internal Console\n\n"
File "/usr/local/lib/python3.5/site-packages/spyderlib/plugins/console.py", line 79, in init
self.find_widget.set_editor(self.shell)
File "/usr/local/lib/python3.5/site-packages/spyderlib/widgets/findreplace.py", line 250, in set_editor
from spyderlib.qt.QtWebKit import QWebView
File "/usr/local/lib/python3.5/site-packages/spyderlib/qt/QtWebKit.py", line 10, in
from PyQt5.QtWebKitWidgets import QWebPage, QWebView # analysis:ignore
ImportError: dlopen(/usr/local/lib/python3.5/site-packages/PyQt5/QtWebKitWidgets.so, 2): Library not loaded: /usr/local/opt/qt5/lib/QtWebKitWidgets.framework/Versions/5/QtWebKitWidgets
Referenced from: /usr/local/lib/python3.5/site-packages/PyQt5/QtWebKitWidgets.so
Reason: image not found

How should I install the QtWebKitWidgest?

TPeterW commented Mar 20, 2016

I apparently am missing the QtWebKit and QtWebKitWidgest with the latest Qt5.6.0 and PyQt5.5.1, and I got the following error when I tried to run spyder

Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/spyderlib/spyder.py", line 3119, in main
mainwindow = run_spyder(app, options, args)
File "/usr/local/lib/python3.5/site-packages/spyderlib/spyder.py", line 3005, in run_spyder
main.setup()
File "/usr/local/lib/python3.5/site-packages/spyderlib/spyder.py", line 822, in setup
message=_("Spyder Internal Console\n\n"
File "/usr/local/lib/python3.5/site-packages/spyderlib/plugins/console.py", line 79, in init
self.find_widget.set_editor(self.shell)
File "/usr/local/lib/python3.5/site-packages/spyderlib/widgets/findreplace.py", line 250, in set_editor
from spyderlib.qt.QtWebKit import QWebView
File "/usr/local/lib/python3.5/site-packages/spyderlib/qt/QtWebKit.py", line 10, in
from PyQt5.QtWebKitWidgets import QWebPage, QWebView # analysis:ignore
ImportError: dlopen(/usr/local/lib/python3.5/site-packages/PyQt5/QtWebKitWidgets.so, 2): Library not loaded: /usr/local/opt/qt5/lib/QtWebKitWidgets.framework/Versions/5/QtWebKitWidgets
Referenced from: /usr/local/lib/python3.5/site-packages/PyQt5/QtWebKitWidgets.so
Reason: image not found

How should I install the QtWebKitWidgest?

@RAMCelorio

This comment has been minimized.

Show comment
Hide comment
@RAMCelorio

RAMCelorio Jun 11, 2016

Hi,
I had an error after trying to run the following command:
python3 configure.py --destdir ~/.env/ariane_mail/lib/python3.4/site-packages --qmake ~/Qt5.2.1/5.2.1/clang_64/bin/qmake

../qpy/QtCore/qpycore_public_api.h:26:10: fatal error: 'sip.h' file not found

include <sip.h>

     ^

1 error generated.
make[1]: *** [qpycore_post_init.o] Error 1
make: *** [sub-QtCore-make_first-ordered] Error 2

Could you help me, please?

Hi,
I had an error after trying to run the following command:
python3 configure.py --destdir ~/.env/ariane_mail/lib/python3.4/site-packages --qmake ~/Qt5.2.1/5.2.1/clang_64/bin/qmake

../qpy/QtCore/qpycore_public_api.h:26:10: fatal error: 'sip.h' file not found

include <sip.h>

     ^

1 error generated.
make[1]: *** [qpycore_post_init.o] Error 1
make: *** [sub-QtCore-make_first-ordered] Error 2

Could you help me, please?

@SaundersB

This comment has been minimized.

Show comment
Hide comment
@SaundersB

SaundersB Aug 24, 2016

Thank you for this. Extremely helpful. I originally had tried to do this without a virtual environment, but after setting up a virtual environment and setting Python to version 3.5 in that environment, it worked.

Also, @TPeterW, apparently QtWebKit was deprecated. See http://stackoverflow.com/questions/37876987/cannot-import-qtwebkitwidgets-in-pyqt5.

SaundersB commented Aug 24, 2016

Thank you for this. Extremely helpful. I originally had tried to do this without a virtual environment, but after setting up a virtual environment and setting Python to version 3.5 in that environment, it worked.

Also, @TPeterW, apparently QtWebKit was deprecated. See http://stackoverflow.com/questions/37876987/cannot-import-qtwebkitwidgets-in-pyqt5.

@neborion

This comment has been minimized.

Show comment
Hide comment
@neborion

neborion Sep 2, 2016

@hantsaniala did you solve your problem about :
Error: Failed to determine the detail of your Qt installation. Try again using the --verbose flag to see more detail about the problem.
I have the same issue. Please, anyone could help me ?
Anyway, what is the "Verbose flag ?"

neborion commented Sep 2, 2016

@hantsaniala did you solve your problem about :
Error: Failed to determine the detail of your Qt installation. Try again using the --verbose flag to see more detail about the problem.
I have the same issue. Please, anyone could help me ?
Anyway, what is the "Verbose flag ?"

@tkarl

This comment has been minimized.

Show comment
Hide comment
@tkarl

tkarl Nov 29, 2016

Hi there,

Im unable to create C++ code while installing PyQt5 Python3 on OS X and Py2APP

Here is the error that I get and and I have no other explanations. Please Help!

/Library/Frameworks/Python.framework/Versions/3.5/bin. The interpreter used by pyuic5 is python3.5. Generating the C++ source for the QtCore module... /Library/Frameworks/Python.framework/Versions/3.6/bin/sip -w -f -t WS_MACX -t Qt_5_7_0 -B Qt_6_0_0 -P -o -y QtCore.pyi -c /Users/grit/Desktop/asd/PyQt5_gpl-5.7/QtCore -I sip -I /Users/grit/Desktop/asd/PyQt5_gpl-5.7/sip /Users/grit/Desktop/asd/PyQt5_gpl-5.7/sip/QtCore/QtCoremod.sip sip: Deprecation warning: /Users/grit/Desktop/asd/PyQt5_gpl-5.7/sip/QtCore/QtCoremod.sip:23: %Module version numbers are deprecated and ignored Error: Unable to create the C++ code.

tkarl commented Nov 29, 2016

Hi there,

Im unable to create C++ code while installing PyQt5 Python3 on OS X and Py2APP

Here is the error that I get and and I have no other explanations. Please Help!

/Library/Frameworks/Python.framework/Versions/3.5/bin. The interpreter used by pyuic5 is python3.5. Generating the C++ source for the QtCore module... /Library/Frameworks/Python.framework/Versions/3.6/bin/sip -w -f -t WS_MACX -t Qt_5_7_0 -B Qt_6_0_0 -P -o -y QtCore.pyi -c /Users/grit/Desktop/asd/PyQt5_gpl-5.7/QtCore -I sip -I /Users/grit/Desktop/asd/PyQt5_gpl-5.7/sip /Users/grit/Desktop/asd/PyQt5_gpl-5.7/sip/QtCore/QtCoremod.sip sip: Deprecation warning: /Users/grit/Desktop/asd/PyQt5_gpl-5.7/sip/QtCore/QtCoremod.sip:23: %Module version numbers are deprecated and ignored Error: Unable to create the C++ code.

@tauruswang

This comment has been minimized.

Show comment
Hide comment
@tauruswang

tauruswang Aug 1, 2018

sip: Deprecation warning: /Users/jerryw/OpenSourceProjects/qtbuild/PyQt5_gpl-5.6/sip/QtCore/QtCoremod.sip:23: %Module version numbers are deprecated and ignored. I think it should use the sip 4.18. the link is http://pyqt.sourceforge.net/Docs/sip4/incompatibilities.html

sip: Deprecation warning: /Users/jerryw/OpenSourceProjects/qtbuild/PyQt5_gpl-5.6/sip/QtCore/QtCoremod.sip:23: %Module version numbers are deprecated and ignored. I think it should use the sip 4.18. the link is http://pyqt.sourceforge.net/Docs/sip4/incompatibilities.html

@tauruswang

This comment has been minimized.

Show comment
Hide comment
@tauruswang

tauruswang Aug 1, 2018

commet the fjile sipQtCoreQt.cpp generated by the sip for the build QT version 5.10.0_1
//{sipName_WindowCancelButtonHint, static_cast(Qt::WindowCancelButtonHint), 418},
//{sipName_WindowOkButtonHint, static_cast(Qt::WindowOkButtonHint), 418},

commet the fjile sipQtCoreQt.cpp generated by the sip for the build QT version 5.10.0_1
//{sipName_WindowCancelButtonHint, static_cast(Qt::WindowCancelButtonHint), 418},
//{sipName_WindowOkButtonHint, static_cast(Qt::WindowOkButtonHint), 418},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment