Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
642 views
in Technique[技术] by (71.8m points)

python - ImportError: No module named PyQt5 - OSX Mavericks

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...