3

I'm trying to get PyQt5 running on OSX. I downloaded and installed the Qt5 binaries. Then, I downloaded the latest SIP source, compiled and installed it. Finally, I downloaded the latest version of PyQt, compiled, and installed it.

python configure.py --qmake /Users/jsmaupin/Qt/5.1.1/clang_64/bin/qmake --sip /System/Library/Frameworks/Python.framework/Versions/2.7/bin/sip

I'm trying to get this to run on the default Python 2.7 installation. It looks like the files were installed into the correct location (as far as I can tell) at /System/Library/Frameworks/Python.framework/Versions/2.7/share/sip/PyQt5/

However, whenever I try to import anything from PyQt5 python reports that it cannot find PyQt5

The code:

from PyQt5 import QtCore

The result:

from PyQt5 import QtCore
    ImportError: No module named PyQt5

I'm a Python newbie, so help is greatly appreciated!

jsmaupin
  • 468
  • 1
  • 8
  • 17

3 Answers3

3

Okay, I hammered at this until I finally found a solution. It seems like this might be a bug in the PyQt library installation or somewhere else. I created a $PYTHONPATH environment variable to point to the newly installed PyQt .py files that hold references to the all of the Qt bindings.

export set PYTHONPATH=$PYTHONPATH:/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

After that, everything worked like magic. This includes PyCharm after going to Settings->Project Interpreter->Python Interpreters->Paths (tab), and clicking the "Reload list of paths" button with the blue circular arrows on the bottom.

jsmaupin
  • 468
  • 1
  • 8
  • 17
  • I had this problem in PyCharm, it turns out the python interpreter being used was the one from my /usr/bin/python folder rather than the python version PyQt4 (in my case) was installed against, so watch out for it if you're still having problems – ElFik May 29 '14 at 18:07
2

An option is to download Anaconda. It automatically come with PyQt5. I found this to be the most simple way to obtain it. https://www.continuum.io/downloads

If you decide to use PyQt5 this way, you will have to use the IDE on Anaconda. I personally enjoy using Spyder (comes with Anaconda) as my IDE.

J. Doe
  • 338
  • 2
  • 4
  • 9
  • good answer i read different topics and tried different ways to install pyqt but they did not work. now it’s working with anaconda from https://www.anaconda.com/distribution/ – myUser Jun 02 '19 at 11:52
2

On macos I find I have to do both:

  • Install PyQt5 from $ brew install PyQt5
  • Ideally in a virtualenv run $(pygui) pip install PyQt5

in order for the module to be imported