Skip to content

Instantly share code, notes, and snippets.

@guillaumevincent
Last active October 28, 2023 12:05
Show Gist options
  • Save guillaumevincent/10983814 to your computer and use it in GitHub Desktop.
Save guillaumevincent/10983814 to your computer and use it in GitHub Desktop.
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"
Copy link

ghost commented Oct 15, 2015

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

@forrestzhang
Copy link

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
Copy link

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

@sancholito
Copy link

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
Copy link

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

@cy-goh
Copy link

cy-goh commented 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.

@hantsaniala
Copy link

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
Copy link

Many thanks for this :-)

@TPeterW
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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