PyQt5 and QtGui module not found

谁说胖子不能爱 提交于 2019-11-27 14:27:32
Ninga

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.

kentop

Configure pyqt with this command:

python[3] configure.py --qmake=[path to Qt5.x]/bin/qmake --verbose

Whether a qt module builds or not depends on the configure.py's check. Take a look at the terminal output and you will find the reason why QtGui..QtWidgets was not installed correctly.

The problem was when I was running the PyQt5 configure script. The correct option to pass went like this:

> python3 configure.py --qmake [path to Qt5.x]/bin/qmake

I was providing the path up to bin, but did not specifically point to qmake. Go figure!

After running the configure script like this, I was able to import all the PyQt5 modules.

raidsan

same issue, python run py ok, but in all IDE: visual studio code/PyCharm. It will show syntax error.

Finally I solved it by set env var PYTHONPATH to python site-packages path, e.g.

PYTHONPATH=D:\Anaconda3\Lib\site-packages

in PyQt5, QtGui and QtCore is located into the QtWidgets

You should import like this:

from PyQt5.QtWidgets import QtGui, QtCore

instead of

from PyQt5.QtCore import *
from PyQt5.QtGui import *

Hope this helps. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!