8

我在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
4

4 回答 4

5

apt install python-pyqt5.qtwebkit

于 2016-10-12T09:38:45.230 回答
4

仔细检查以确保您系统上的 Qt 安装已构建 Webkit 库。

此外,检查以确保 QtWebKit.so 存在于您的 python2.6/site-packages/PyQt4 目录中。

于 2010-05-27T16:05:52.293 回答
1

安装 python 模块PySide,例如:

pip install PySide

然后将您的导入更改为:

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,因为上述基本上只是解决方法。

于 2019-05-11T18:56:11.200 回答
0

从 atrpms el5 repo 安装 qt44/qt44-x11/qt44-devel rpms。

http://atrpms.net/dist/el5/qt4/

于 2010-08-15T23:45:49.610 回答