ImportError: No module named QtWebKit

前端 未结 4 1482
隐瞒了意图╮
隐瞒了意图╮ 2021-01-02 15:43

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
<
相关标签:
4条回答
  • 2021-01-02 16:18

    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.

    0 讨论(0)
  • 2021-01-02 16:29

    apt install python-pyqt5.qtwebkit

    0 讨论(0)
  • 2021-01-02 16:34

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

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

    0 讨论(0)
  • 2021-01-02 16:41

    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.

    0 讨论(0)
提交回复
热议问题