PyQt5 : QWebEngineView doesn't load URL

Viewed 376

I'm trying to make a browser, using Python 3.10.4 & PyQt5 v5.15.6, in a virtual environment (venv).

My problem is that QWebEngineView doesn't load URL, so I just have a blank window.

Here is my code:

import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *


class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.browser = QWebEngineView()
        self.browser.load(QUrl('https://www.google.com'))
        self.browser.loadFinished.connect(self.test)
        self.setCentralWidget(self.browser)
        self.showMaximized()

    def test(self):
        print('super')


app = QApplication(sys.argv)
QApplication.setApplicationName('Jello')
window = MainWindow()
app.exec_()

Do you have any idea of a solution for that? I've walked through many web pages without finding any lead.

Thanks!

1 Answers

You didn't mention your OS and version, but I've seen this error in Ubuntu 22.04. Try installing PyQtWebEngine via system package and running your code outside the virtual environment. In Ubuntu:

sudo apt install python3-pyqt5.qtwebengine
Related