22

I am trying to install PyQt5 on my Mac but I do not know how to use it well. I have tried to install sip doing

cd ~/Downloads/sip-4.17
python configure.py

which worked, and then I tried

cd ~/Downloads/PyQt-gpl-5.5.1
python configure.py --qmake /Users/name/Qt/5.5/clang_64/bin/qmake

which returns an error that says

Make sure you have a working sip on your PATH or use the --sip argument to explicitly specify a working sip.

How do I fix this error? Did I not install sip?

user2888499
  • 369
  • 1
  • 2
  • 9

6 Answers6

41

Meanwhile I have the ultimate way to install PyQt5 on macOS. Don't use Homebrew. It is great for installing Qt5, but for PyQt5 the best way to install it is using

python3 -m pip install PyQt5

This works very quickly and uses universal Python Wheels:

Collecting PyQt5
  Downloading PyQt5-5.9-5.9.1-cp35.cp36.cp37-abi3-macosx_10_6_intel.whl 
(82.2MB)
    100% |████████████████████████████████| 82.2MB 17kB/s 
Collecting sip<4.20,>=4.19.3 (from PyQt5)
  Downloading sip-4.19.3-cp36-cp36m-macosx_10_6_intel.whl (49kB)
    100% |████████████████████████████████| 51kB 1.2MB/s 
Installing collected packages: sip, PyQt5
Successfully installed PyQt5-5.9 sip-4.19.3

You see: Such a wheel is re-used for CPython 3.5, 3.6 and 3.7.

Old remark, but see below: PySide2 is not as far, but we will build similar wheels when we have the first version ready.

Added on 2017/09/25: You can of course also use

pip3 install PyQt5

But at that time my pip/pip2/pip3 was a bit messy linked, so the first solution is rock solid and avoids confusion.

Also right is that you don't always get the lastest version of PyQt5 this way. But for getting started, the priority is to get results quickly and not the bleeding edge.

Update: PySide2 now officially has wheels, to:

$ python3 -m pip install PySide2
Collecting pyside2
  Downloading https://files.pythonhosted.org/packages/2a/e2/2dc134a5c475f661d5ff2ab587fbd2c285db3d064e03ac9b4a2ee0958400/PySide2-5.12.2-5.12.2-cp35.cp36.cp37-abi3-macosx_10_12_intel.whl (109.8MB)
    100% |████████████████████████████████| 109.8MB 238kB/s 
Collecting shiboken2==5.12.2 (from pyside2)
  Downloading https://files.pythonhosted.org/packages/bd/8b/a2ad76c3a935fae51f0ed9b150a9df08167c4550fcd07637f0db19c31849/shiboken2-5.12.2-5.12.2-cp35.cp36.cp37-abi3-macosx_10_12_intel.whl (691kB)
    100% |████████████████████████████████| 696kB 1.6MB/s 
Installing collected packages: shiboken2, pyside2
Successfully installed pyside2-5.12.2 shiboken2-5.12.2

If you see bugs or differences between the two, please feel free to open a bug report. Follow the instructions on https://wiki.qt.io/Qt_for_Python/Reporting_Bugs

Christian Tismer
  • 1,305
  • 14
  • 16
  • No, in my case. SIP doesn't follow. I have to home-brew later. – Polv Jul 17 '18 at 11:54
  • This is not true. I just tried it again. Works like a charm with pip. There is only one drawback: You get the .pyi stub files only with the brew version. – Christian Tismer Jul 17 '18 at 17:01
  • » pip install PyQt5 Collecting PyQt5 Could not find a version that satisfies the requirement PyQt5 (from versions: ) No matching distribution found for PyQt5 – swpalmer Feb 05 '20 at 18:04
  • Please bear with me for a very uninformed question. Would that install all that is needed to get started with Python 3 and Qt, or is it just about Python bindings for a separately installed and supposed pre existent Qt5 installation? – mico Feb 10 '20 at 10:03
  • @mico I think it will install PyQt5 and Qt5 also on Windows, at least PySide2 does that. You need to install Python 3.X yourself. – Christian Tismer Feb 20 '20 at 15:38
  • I'm on macOS Big Sur … I did this (and tried homebrew as well which seemed install but "import PyQt5" fails in ) and it is giving me errors: Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... error error: subprocess-exited-with-error × Preparing metadata (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [29 lines of output] – wide_eyed_pupil Mar 18 '22 at 07:38
  • My answer is now 6 years old, and Big Sur is its own beast. Better open a new question and don't expect that answers are eternal :) – Christian Tismer Mar 18 '22 at 12:20
  • This post is still accurate, but I should add that updating to the newest version of python can be necessary for the pip command to work properly. So, if it's still giving you errors, check for updates before giving up – Ryan Ogden Sep 02 '22 at 21:11
  • On Monterey `python3 -m pip install PyQt5` fails for me, with the error `ModuleNotFoundError: No module named 'sipbuild'`. However, `brew install pyqt5` as described below works for me. – sh37211 Oct 27 '22 at 17:40
33

I'm kind of dodging the question, but the simplest way is to install Homebrew, and just run brew install pyqt or brew install pyqt5.

hgiesel
  • 5,430
  • 2
  • 29
  • 56
  • 1
    Disclaimer: This will install python 3.x on your system, as it seems to be listed as a dependency. I myself was quite surprised, as i thought PyQT5 supported python>2.6. Not sure if noob or just stupid. – Kraay89 Dec 01 '16 at 22:05
  • How do I import this in my python script? My code cannot find the module. – Tino Caer Jul 12 '17 at 03:25
  • @TinoCaer probably you are running the wrong python; try `python --version` and see if it match the python required by your QT version –  Jul 12 '17 at 18:43
  • 1
    Sorry, I really think Christian's answer is better. pip3 is much cleaner, faster and simpler. – Tim Sep 28 '17 at 17:49
  • Thanks, Tim! And it is worth mentioning that it is really against Python's way to install it. Meanwhile people are trying to build a PySide2 install with homebrew, too. What a bad idea since we are building wheels for Python. There should be _one_ standard way for all platforms... – Christian Tismer Feb 01 '18 at 18:25
4

You need to install SIP first, which is not just running configure.py:

>>> cd ~/Downloads/sip-4.17
>>> python configure.py
>>> make
>>> make install

Then you can install PyQt5:

>>> cd ~/Downloads/PyQt-gpl-5.5.1
>>> python configure.py --qmake /Users/name/Qt/5.5/clang_64/bin/qmake
>>> make
>>> make install
gary
  • 4,227
  • 3
  • 31
  • 58
Daniele Pantaleone
  • 2,657
  • 22
  • 33
  • 1
    Yes this should be the accepted answer. Installing PyQt using brew will be a bit of a mess I think (using brew for python lib is a bad idea IMO). Installing Qt using brew can be done but the formula is not up to date with the pyqt sources (5.8.0 vs 5.8.2) – melMass Apr 19 '17 at 09:48
  • So I just tried this and I couldn't really manage to install it this way. In the end I just had to enter `sudo python3 pip3 install PyQt5` – Rich_Rich Jul 11 '17 at 12:16
  • @Rich_Rich You should avoid sudo. With Python, you can install a virtualenv once and then use that all the time. But if your _brew_ command is correctly installed (check this with _brew doctor_ !), then the brewed Python should work fine, even without virtualenv and without sudo. – Christian Tismer Feb 01 '18 at 18:30
1

Qt is set of cross-platform C++ libraries that implement high-level APIs for accessing many aspects of modern desktop and mobile systems. These include location and positioning services, multimedia, NFC and Bluetooth connectivity, a Chromium based web browser, as well as traditional UI development.

PyQt5 is a comprehensive set of Python bindings for Qt v5. It is implemented as more than 35 extension modules and enables Python to be used as an alternative application development language to C++ on all supported platforms including iOS and Android.

PyQt5 may also be embedded in C++ based applications to allow users of those applications to configure or enhance the functionality of those applications.

     brew install PyQt5 (or) pip3 install PyQt5
Tamil Selvan S
  • 562
  • 8
  • 25
0

In ~/.pip/pip.log I discovered:

Skipping https://pypi.python.org/packages/... (from https://pypi.python.org/simple/pyqt5/) because it is not compatible with this Python

Simply installed newwer version of Python 3 from official website and pip3 install PyQt5 finally worked.

Benny K
  • 1,107
  • 12
  • 9
0

Qt has a Mac .dmg installer with all the components. I uninstalled my pip version first, and installed my Qt into the standard location - I tried putting into /opt/Qt as suggested by another post, but it failed due to changes to MacOS rights in Mojave. There is an expansion triangle next to the Qt item which allows for installing Designer separately from the Qt engine and the 2D/3D development and platform-specific tools.

Qt Installer:

https://www.qt.io/download-qt-installer

Community
  • 1
  • 1
RWorden
  • 11
  • 3