3
votes

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!

3

3 Answers

3
votes

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.

2
votes

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.

1
votes

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