Mac OS pyQt 4.x or 5.x: Solving typical problems (ImportError: No module named PyQt4)

  • Post published:May 27, 2014

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

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

pyrcc4 mainwindow.qrc -o

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