Is there some reason that QtGui is packaged with PyQt5???
是否有一些原因导致QtGui与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:
我正在使用Mark Summerfield的快速GUI编程书籍。显然这本书是用Qt4写的,但是我被推荐使用Qt5和PyQt5。我想在第4章中运行第一个示例代码。代码从以下导入语句开始:
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.
注意,PyQt5。QtCore导入语句不会产生错误。
From the terminal,
从终端,
$ echo $PYTHONPATH
:/usr/lib/python3.3/site-packages
Has anybody else come across this import error for QtGui?
还有其他人遇到过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.
但是我没有QtWidgets, QtGui, QtWebkit, QtDesigner,还有其他几个。
Also, if it is helpful, the contents of /usr/lib/python3.3/site-packages/PyQt5 are:
另外,如果它是有用的,那么/usr/lib/python3 /site-package /PyQt5的内容是:
__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?
它们是我能够导入的相同模块。其他模块(QtWidgets、QtGui等)是否也在这里?
I am using Ubuntu 13.04 and Python 3.3.
我使用的是Ubuntu 13.04和Python 3.3。
5 个解决方案
#1
3
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.
当第一次尝试pyqt4和pyqt5和pycharm IDE时,我遇到了许多进口问题。(尽管导入没有从IDLE中运行的prob),最终在大量填充、卸载和重新安装(包括依赖项)之后,导入将自己整理出来。
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...
您是否使用pyqt网站的安装程序安装pyqt5 ?你必须。Qt设计器是在windows的开始菜单下找到的。在使用PyQt4教程时,我很幸运地使用了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.
我自己是新手,但在pyqt4中,QtWidget是QtGui (QtGui.QtWidget)的一部分,在pyqt5中,它被作为QtWidgets导入。在pyqt5中获得pyqt4教程的代码只有很小的变化。
I personally went back to pYqt4 to take advantage of pyqtgraph.
我亲自回到pYqt4去利用pyqtgraph。
Look at my pyqt4 post here which walks you through using Qt Designer.
看看我的pyqt4帖子,它会让你使用Qt设计器。
#2
2
Configure pyqt with this command:
配置pyqt与此命令:
python[3] configure.py --qmake=[path to Qt5.x]/bin/qmake --verbose
python[3]配置。py——qmake =[Qt5之路。x)/ bin / qmake——冗长
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.
qt模块是否构建取决于配置。py支票。看一下终端输出,你会发现为什么QtGui…QtWidgets没有正确安装。
#3
1
The problem was when I was running the PyQt5 configure script. The correct option to pass went like this:
问题是当我运行PyQt5配置脚本时。通过的正确选项是这样的:
> 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!
我提供了通往bin的路径,但没有具体指向qmake。去图!
After running the configure script like this, I was able to import all the PyQt5 modules.
在运行这个配置脚本之后,我能够导入所有PyQt5模块。
#4
-3
in PyQt5, QtGui and QtCore is located into the QtWidgets
在PyQt5中,QtGui和QtCore位于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. :)
希望这个有帮助。:)
#5
-3
My sort of similar error was caused by not fully completing the PySide installation. This fixed it for me:
我的类似的错误是由于没有完全完成PySide安装。这是为我准备的:
$ pyside_postinstall.py -install
#1
3
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.
当第一次尝试pyqt4和pyqt5和pycharm IDE时,我遇到了许多进口问题。(尽管导入没有从IDLE中运行的prob),最终在大量填充、卸载和重新安装(包括依赖项)之后,导入将自己整理出来。
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...
您是否使用pyqt网站的安装程序安装pyqt5 ?你必须。Qt设计器是在windows的开始菜单下找到的。在使用PyQt4教程时,我很幸运地使用了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.
我自己是新手,但在pyqt4中,QtWidget是QtGui (QtGui.QtWidget)的一部分,在pyqt5中,它被作为QtWidgets导入。在pyqt5中获得pyqt4教程的代码只有很小的变化。
I personally went back to pYqt4 to take advantage of pyqtgraph.
我亲自回到pYqt4去利用pyqtgraph。
Look at my pyqt4 post here which walks you through using Qt Designer.
看看我的pyqt4帖子,它会让你使用Qt设计器。
#2
2
Configure pyqt with this command:
配置pyqt与此命令:
python[3] configure.py --qmake=[path to Qt5.x]/bin/qmake --verbose
python[3]配置。py——qmake =[Qt5之路。x)/ bin / qmake——冗长
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.
qt模块是否构建取决于配置。py支票。看一下终端输出,你会发现为什么QtGui…QtWidgets没有正确安装。
#3
1
The problem was when I was running the PyQt5 configure script. The correct option to pass went like this:
问题是当我运行PyQt5配置脚本时。通过的正确选项是这样的:
> 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!
我提供了通往bin的路径,但没有具体指向qmake。去图!
After running the configure script like this, I was able to import all the PyQt5 modules.
在运行这个配置脚本之后,我能够导入所有PyQt5模块。
#4
-3
in PyQt5, QtGui and QtCore is located into the QtWidgets
在PyQt5中,QtGui和QtCore位于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. :)
希望这个有帮助。:)
#5
-3
My sort of similar error was caused by not fully completing the PySide installation. This fixed it for me:
我的类似的错误是由于没有完全完成PySide安装。这是为我准备的:
$ pyside_postinstall.py -install