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
844 views
in Technique[技术] by (71.8m points)

qt - PyQt5 and QtGui module not found

Is there some reason that QtGui is packaged with PyQt5???

I am using Mark Summerfield's Rapid GUI programming book. Obviously this book was written with Qt4 in mind, but I have been recommended to use Qt5, and PyQt5. I want to run the first example code in chapter 4. The code begins with the following import statements:

import sys
import time
from PyQt5.QtCore import *
from PyQt5.QtGui import *

To which the compiler responds:

Traceback (most recent call last):
  File "wakeUp.py", line 4, in <module>
    from PyQt5.QtGui import *
ImportError: No module named 'PyQt5.QtGui'

Note that the PyQt5.QtCore import statement does not generate an error.

From the terminal,

$ echo $PYTHONPATH
:/usr/lib/python3.3/site-packages

Has anybody else come across this import error for QtGui?

From an interactive session I can

>>> import PyQt5.Qt
>>> import PyQt5.QtDBus
>>> import PyQt5.QtNetwork
>>> import PyQt5.QtXmlPatterns

But I don't have QtWidgets, QtGui, QtWebkit, QtDesigner, and several others.

Also, if it is helpful, the contents of /usr/lib/python3.3/site-packages/PyQt5 are:

__init__.py  QtCore.so  QtDBus.so  QtNetwork.so  Qt.so  QtXmlPatterns.so  uic

which are the same modules that I am able to import. Should the other modules (QtWidgets, QtGui etc) be here too?

I am using Ubuntu 13.04 and Python 3.3.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

When first trying pyqt4 and pyqt5 and the pycharm IDE I had many problems with imports. (although the imports had no prob running from IDLE) Eventually after much stuffing around, uninstalling and reinstalling, (including dependencies) the imports sorted themselves out.

Did you install pyqt5 using an installer from the pyqt website? You must. Qt designer is found under the start menu in windows. When following PyQt4 tutorials, I have had luck using the following import statements for PyQt5...

from PyQt4 import QtCore, QtGui #in the pyqt4 tutorials
from PyQt5 import QtCore, QtGui, QtWidgets #works for pyqt5

I'm new to it myself but in pyqt4, QtWidget was part of QtGui (QtGui.QtWidget), in pyqt5 it gets imported by itself as QtWidgets. Its only a small change in code to get the pyqt4 tutorials working in pyqt5.

I personally went back to pYqt4 to take advantage of pyqtgraph.

Look at my pyqt4 post here which walks you through using Qt Designer.


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

...