24

How can I get to work PyQt 4 or 5 on a Mac with OS X Sierra? It seems that I have to wait for a new version of PyQt but I am not sure if that is actually true.

Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
Bzzzt_90
  • 251
  • 1
  • 2
  • 3

6 Answers6

22

Make sure you have homebrew installed.

Use the following commands:

  1. brew tap cartr/qt4
  2. brew tap-pin cartr/qt4
  3. brew install qt
  4. brew install pyside
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
19

Considering PyQt4 is no longer actively supported by its creators, I'd recommend using PyQt5 (plus I found it much easier to get working). Once you've installed pip3 (you can use easy_install) run the following commands in your terminal:

1) pip3 install sip
2) pip3 install PyQt5

You can then run the following sample app to see if everything is working:

import sys
from PyQt5 import QtWidgets

def main():
    app = QtWidgets.QApplication(sys.argv)
    window = QtWidgets.QMainWindow()
    button = QtWidgets.QPushButton("Hello, PyQt!")
    window.setCentralWidget(button)
    window.show()
    app.exec_()

if __name__ == '__main__':
    main()
Kal
  • 1,176
  • 19
  • 22
  • 1
    This solution worked great for me, couldn't find a cartr PyQt5 version (approach referenced in the top solution) – Mark Essel Apr 21 '20 at 16:01
7

The easiest way to install PyQt (4 or 5) on OSX is probably using Homebrew. This will also install a separate standalone Python from the system Python, meaning it will continue to work without problems following any future system updates.

According to this thread PyQt4 is no longer supported on macOS Sierra, but PyQt5 will still work.

Once you've installed Homebrew, you can install PyQt5 with the following:

brew install pyqt5 # for PyQt5

enter image description here

mfitzp
  • 15,275
  • 7
  • 50
  • 70
  • 10
    @Parsa it is what I used to install it on my own laptop with macOS Sierra. Sorry it doesn't work for you, but no need for the snark. Post your own solution if you have one. – mfitzp Oct 14 '16 at 07:05
3

I managed to get Qt5 with PyQt5 installed (on both 10.10.5 and 10.12) using these steps, which I learned from https://gist.github.com/guillaumevincent/10983814:

  1. Install Xcode (required by Qt5 installer)
  2. Install Python 3 from https://www.python.org/downloads/ (includes pip3 command)
  3. Install Qt5 from https://www.qt.io/
  4. Install SIP (pip3 install SIP)
  5. Install PyQt (pip3 install PyQt5)

This also made commands such as pyuic5 available in Terminal.app (requires re-opening the Terminal window once to recognize the new search paths).

Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
1

If you still get the import error, you should also add

PYTHONPATH="${PYTHONPATH}:/usr/local/lib/python2.7/site-packages/"
export PYTHONPATH

to your ~/.bash_profile file after you applied the above stated steps, then it should work fine (make sure that PyQt4 is installed in that folder). I have installed python with conda and this import error seems to be related to anaconda.

Dennis Tsoi
  • 1,349
  • 2
  • 11
  • 17
Kristina
  • 11
  • 1
1

1:

brew install cartr/qt4/pyqt
brew link qt@4

2: go here and download https://riverbankcomputing.com/software/sip/download

and do

tar -xzvf sip-4.19.6.tar.gz
cd sip-4.19.6
python configure.py
make
make install

3: go here and download : https://riverbankcomputing.com/software/pyqt/download

and do

tar -xzvf PyQt4_gpl_mac-4.12.1.tar.gz
cd PyQt4_gpl_mac-4.12.1
python configure.py
make
make install

4: test in python:

import sys;
from PyQt4 import QtGui;

def pyqtDemo():
    app = QtGui.QApplication(sys.argv);

    w = QtGui.QWidget();
    w.resize(250, 150);
    w.move(300, 300);
    w.setWindowTitle('Hello World');
    w.show();

    sys.exit(app.exec_());

pyqtDemo()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
MCJ
  • 43
  • 1
  • 6