ImportError: No module named QtWebKit

前端 未结 4 1590
隐瞒了意图╮
隐瞒了意图╮ 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: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.

提交回复
热议问题