Solving PyQt5 ImportError: No module named ‘PyQt5.QtWebKitWidgets’ in Python

ImportError: No module named ‘PyQt5.QtWebKitWidgets’ in Python is an error which occurs when you are working with specific deprecated modules.

In this article I am going to help you solve this error and understand the root of the problem, also I am presenting other possible solutions that may work if the main solution does not work for you.

Exploring the ImportError: No module named ‘PyQt5.QtWebKitWidgets’ in Python

First of all we need to understand why the error happens at all, the error happens when you work with deprecated modules like QtWebKitWidgets.

The error message should look like the message bellow.

                                                                       #
No module named 'PyQt5.QtWebKitWidgets'
                                                                       #

In the sections bellow we will explain the root of the error more and propose some possible fixes.

Solution 1 : Replace the deprecated QtWebKitWidgets

The solution is simple, since QtWebKitWidgets has been removed from PyQt, You should replace the code bellow.

                                                                       #
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from PyQt5.QtWebKit import QWebSettings
                                                                       #

With the following code :

                                                                       #
from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView,QWebEnginePage as QWebPage
from PyQt5.QtWebEngineWidgets import QWebEngineSettings as QWebSettings
                                                                       #

If the solution does not work for you, make sure to try the following solution.

Solution 2 : install PyQtWebEngine and PyQt

The second solution is to install PyQtWebEngine using pip and install the last version of PyQt

The solution is to run the following command and see if the error persists

                                                                       #
pip install PyQtWebEngine
                                                                       #

If the error persists then try this one.

                                                                       #
pip install PyQt5==6.3.0
                                                                       #

I hope this solution has worked for you, try the solution bellow if that is not the case.

Solution 3 : use PyQt5.QtWebKitWidgets.QWebView

The third solution is to replace QtWebKit with PyQt5.QtWebKitWidgets.QWebView.

You can use PyQt5.QtWebEngineWidgets.QWebEngineView in the source code but you need additional adjustments.

This should be enough to get rid of the error if you do it properly.

Summing-up

I hope this article has helped you achieve your objective, If you like the effort we did here, please consider donating to our Kofi account located at the top of this page.

Keep coding, cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/