我在centos5上。我用make altinstall安装了python26源代码。然后我做了一个:
yum install qt4
yum install qt4-devel
yum install qt4-doc
来自riverbankcomputing.co.uk我下载了sip 4.10.2的源代码,编译并安装得很好。然后从我从源PyQt-x11-4.7.3
下载和编译的同一站点两个安装都使用python26版本(/usr/local/bin/python2.6)。所以configure.py,make和make install都没有错误。最后,我尝试运行此脚本,但在这篇文章的主题中得到了错误:
import sys
import signal
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import QWebPage
def onLoadFinished(result):
if not result:
print "Request failed"
sys.exit(1)
#screen = QtGui.QDesktopWidget().screenGeometry()
size = webpage.mainFrame().contentsSize()
# Set the size of the (virtual) browser window
webpage.setViewportSize(webpage.mainFrame().contentsSize())
# Paint this frame into an image
image = QImage(webpage.viewportSize(), QImage.Format_ARGB32)
painter = QPainter(image)
webpage.mainFrame().render(painter)
painter.end()
image.save("output2.png")
sys.exit(0)
app = QApplication(sys.argv)
signal.signal(signal.SIGINT, signal.SIG_DFL)
webpage = QWebPage()
webpage.connect(webpage, SIGNAL("loadFinished(bool)"), onLoadFinished)
webpage.mainFrame().load(QUrl("http://www.google.com"))
sys.exit(app.exec_())
即使在pyqt4的配置开始时,我也看到它应该安装QtWebKit,但显然它不是?发生了什么事?
我刚做了一个发现,看起来好像没有安装。我有什么选择?
[root@localhost ~]# find / -name '*QtWebKit*'
/root/PyQt-x11-gpl-4.7.3/sip/QtWebKit
/root/PyQt-x11-gpl-4.7.3/sip/QtWebKit/QtWebKitmod.sip
/root/PyQt-x11-gpl-4.7.3/cfgtest_QtWebKit.cpp
答案 0 :(得分:6)
apt install python-pyqt5.qtwebkit
答案 1 :(得分:3)
仔细检查以确保系统上的Qt安装已构建Webkit库。
另外,请检查以确保python2.6 / site-packages / PyQt4目录中存在QtWebKit.so。
答案 2 :(得分:0)
从atrpms el5 repo安装qt44 / qt44-x11 / qt44-devel rpms。
答案 3 :(得分:0)
安装python模块PySide
,例如:
pip install PySide
adn然后从以下位置更改导入:
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import QWebPage
收件人:
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtWebKit import QWebPage
或者,您也可以使用PySide进行回退, 因此您也可以使代码与旧系统兼容:
try:
# NOTE We need to try importing QtWebKit first,
# because it is the most likely one to not be available,
# and all used QT classes need to come from the same module,
# to be compatible with each other.
from PyQt4.QtWebKit import QWebPage
from PyQt4.QtCore import *
from PyQt4.QtGui import *
except ImportError:
try:
from PySide.QtGui import *
from PySide.QtWebKit import QWebPage
except ImportError:
raise Exception("We require PyQt4 (with QtWebKit) or PySide")
注意从长远来看,您应该更改为QT5,因为上述基本上只是解决方法。