Cannot Import Qtwebkitwidgets in Pyqt5

Cannot import QtWebKitWidgets in PyQt5

QtWebKit got deprecated upstream in Qt 5.5 and removed in 5.6.

You may want to switch to PyQt5.QtWebEngineWidgets.QWebEngineView.

For basic use of PyQt5.QtWebKitWidgets.QWebView, it can simply be updated to use PyQt5.QtWebEngineWidgets.QWebEngineView in the source code, but there may be some differences in the new component which require further adjustments.

QtWebEngineWidgets importError

You may try running it on Python 3.7, if you are using a version later than that. (I've been having this exact error despite following the "fixes" in other posts, but once I used Python 3.7 and PyQt5==5.15.0 my application ran without issue.)

Can't start spyder because of PyQt5.QtWebKitWidgets

I swapped Pyqt5 version from 5.12 to 5.11.2 with:

py -m pip install pyqt5==5.11.2

And now it works...

Python PyQt5 cannot import name 'QWebView'

There are two different web toolkits for Qt5: QtWebKit based on WebKit and the newer QtWebEngine based on Chromium.

Your imports seem to mix up those two. QWebPage and QWebView are part of QtWebKit, not of QtWebEngine, which has QWebEngineView and QWebEnginePage.

So you can choose either

  • WebEngine:

    from PyQt5.QtWebEngineWidgets import QWebEnginePage
    from PyQt5.QtWebEngineWidgets import QWebEngineView
  • WebKit:

    from PyQt5.QtWebKitWidgets import QWebPage
    from PyQt5.QtWebKitWidgets import QWebView

The interfaces of those two are largely compatible, but not exactly identical.



Related Topics



Leave a reply



Submit