[MAC] pyQt 4.x or 5.x: Solving typical problems (ImportError: No module named PyQt4)

brew install pyqt

Open up terminal and check:
1. “which python”
-> Wrong: /usr/bin (Apple)
-> Right: /usr/local/bin (brew)

2. “brew doctor”

3. “export”
Setup your PATH correctly to /usr/local/bin before /usr/bin
-> export PATH=/usr/local/bin:/usr/bin:$PATH

I would recommend using QtCreator to setup a drag and drop User Interface (*.ui) File.
Afterwards  we must compile the UI-File into python code (wrap it):

pyuic4 mainwindow.ui -o mainwindow.py

If you have a Resource File QRC- File too you have to previously do:

pyrcc4 mainwindow.qrc -o mainwindow_rc.py

Keep in mind to replace the names according to your filenames 😉 so…

pyrcc4 <resourcefilename>.qrc -o <resourcefilename_rc>.py && pyuic4 <uifilename>.ui -o <uifilename>.py

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.