ImportError: No module named QtWebKit
Asked Answered
C

5

8

I am on centos5. I installed python26 source with a make altinstall. Then I did a:

yum install qt4
yum install qt4-devel
yum install qt4-doc

From riverbankcomputing.co.uk I downloaded the source for sip 4.10.2, compiled and installed fine. Then from the same site I downloaded and compiled from source PyQt-x11-4.7.3

Both installs were using the python26 version (/usr/local/bin/python2.6). So configure.py, make, and make install worked with no errors. Finally, I tried to run this script, but got the error in the subject of this post:

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_())

Even in the beginning of the configure for pyqt4, I saw it say QtWebKit should be installed, but apparently it's not? What's going on?

I just did a find, and it looks like it wasn't installed. What are my options?

[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
Czardom answered 27/5, 2010 at 15:59 Comment(0)
I
4

Double check to make sure that the Qt installation on your system has the Webkit library built.

Also, check to make sure that the QtWebKit.so exists in your python2.6/site-packages/PyQt4 directory.

Incentive answered 27/5, 2010 at 16:5 Comment(3)
From your 'find', it looks like from your system does not have the QtWebKit library from the Qt distribution itself. I don't know CentOS very well but check for a QtWebKit package in your package manager and get that installed. Then you will need to rebuild PyQt4.Incentive
I assumed the QtWebKit was a part of PyQt. Centos uses yum, and I am not sure how to use it much either. I figured yum search webkit would find something, but it doesn't. I am going to remove those packages, and install this, and see what happens. qt.nokia.com/downloadsCzardom
PyQt just wraps the underlying Qt libraries. When you build PyQt, it checks to see what Qt libraries you have installed and then builds the wrappers for what it finds. A quick google for centos 5 and webkit didn't turn up much of anything. Hopefully a CentOS expert will have a better answer for you.Incentive
B
5

apt install python-pyqt5.qtwebkit

Blush answered 12/10, 2016 at 9:38 Comment(1)
why pyqt5 qtwebkit required in PyQt4 ?Telephotography
I
4

Double check to make sure that the Qt installation on your system has the Webkit library built.

Also, check to make sure that the QtWebKit.so exists in your python2.6/site-packages/PyQt4 directory.

Incentive answered 27/5, 2010 at 16:5 Comment(3)
From your 'find', it looks like from your system does not have the QtWebKit library from the Qt distribution itself. I don't know CentOS very well but check for a QtWebKit package in your package manager and get that installed. Then you will need to rebuild PyQt4.Incentive
I assumed the QtWebKit was a part of PyQt. Centos uses yum, and I am not sure how to use it much either. I figured yum search webkit would find something, but it doesn't. I am going to remove those packages, and install this, and see what happens. qt.nokia.com/downloadsCzardom
PyQt just wraps the underlying Qt libraries. When you build PyQt, it checks to see what Qt libraries you have installed and then builds the wrappers for what it finds. A quick google for centos 5 and webkit didn't turn up much of anything. Hopefully a CentOS expert will have a better answer for you.Incentive
I
2

install the python module PySide, for example with:

pip install PySide

adn then change your imports from:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import QWebPage

to:

from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtWebKit import QWebPage

Alternatively you could use PySide just a s a fall back, so you can keep your code compatible with older systems too:

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")

NOTE In the long run you should change to QT5 though, as the above are basically just workarounds.

Involutional answered 11/5, 2019 at 18:56 Comment(0)
D
0

install the qt44/qt44-x11/qt44-devel rpms from the atrpms el5 repo.

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

Drye answered 15/8, 2010 at 23:45 Comment(0)
J
0

In my case, I got this error message when trying to install Electrum on Ubuntu Bionic 18.04. The problem was that the default python version was too old, since the minimum requirement at the time was python 3.8, and thus the commands above installed the wrong (python) version of PyQT5.

The solution was to install

sudo apt-get install -y python3.8 python3.8-dev

After which you can configure default python version by running:

sudo update-alternatives --config python

and maybe

sudo update-alternatives --config python3

After which also the

sudo apt-get install -y python-pyqt5.qtwebkit

worked better. You might also want to try:

pip install python3-pqt5
Jugendstil answered 18/12, 2022 at 9:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.