0

I've been trying to render a webpage onto a widget in PyQt5. These are my settings PyQt : 5.15.4 | PyQtWebEngine : 5.15.4 | PyQt5-tools 5.15.4.2

I'm trying to render out some basic websites like google.com but I'm facing a blank page.

self.google_lib_viewer= QtWebEngineWidgets.QWebEngineView(self.google_lib_tab)
self.google_lib_viewer.setGeometry(QtCore.QRect(0, 0, 656, 411))
self.google_lib_viewer.setObjectName("google_lib_viewer")
self.google_lib_viewer.load(QtCore.QUrl("https://google.com"))

But nothing seems to be visible.

I even tried to create a very normal webpage using PyQt5 but even that comes up blank . I tried uninstalling my PyQt5 packages and reinstalling them , but nothing seem to work . Can someone please help me out on this one!

I have separated the code into a separate code . Please use this for reproducing the issue.

import os, sys
from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import QApplication

app = QApplication(sys.argv)
web = QWebEngineView()

web.load(QUrl("http://google.com"))
web.show()

sys.exit(app.exec_())

I also find a small blink while the web page loads and it again disappears . I think something could be loading by getting closed soon

  • Please provide a [mcve]. You might also want to connect to the various [signals](https://doc.qt.io/qt-6/qwebengineview.html#signals) to monitor the progress of the page loading. – G.M. Feb 04 '22 at 15:38
  • Hi , I have updated the main code with the sample code , so its easier to reproduce. – Nirmal Kumar Feb 04 '22 at 15:48
  • I don't have `PyQt5` installed but the example code you've provided works just fine when I replace `PyQt5` with `PySide2`. – G.M. Feb 04 '22 at 15:57
  • I tried the same with PySide2, but that deosn't work for me as well – Nirmal Kumar Feb 04 '22 at 16:01
  • Then, as I said, you need to connect to the various signals and check for errors etc. – G.M. Feb 04 '22 at 16:03
  • @NirmalKumar What specific platform are you testing on? – ekhumoro Feb 04 '22 at 16:46
  • I'm testing this on Windows . Tools Versions Python 3.6.7 | PyQt : 5.15.4 | PyQtWebEngine : 5.15.4 | PyQt5-tools 5.15.4.2 – Nirmal Kumar Feb 05 '22 at 10:03
  • I also find a small blink while the web page loads and it again disappears . I think something could be loading by getting closed soon. – Nirmal Kumar Feb 05 '22 at 11:21
  • I can't reproduce this on Linux using python-3.10.2, qt-5.15.2 & pyqt-5.15.6. But there's no reason why the example shouldn't work as expected, so this must be due to a bug that is specific to Windows and/or the versions of Qt/WebEngine you are using. I suggest you try testing with [PyQt6](https://pypi.org/project/PyQt6/) to see if that makes any difference. Also: what **specific** version of Windows are you using? Can you install the Google Chrome browser on your system and check it works okay? Doing that might update some drivers that are used by WebEngine (which is also Chrome-based). – ekhumoro Feb 05 '22 at 19:28
  • I'm on Windows 10 and I just tried reinstalling my Chrome , still doesn't help . – Nirmal Kumar Feb 06 '22 at 07:18
  • So, if Chrome works on your system, that would imply that the problem may lie in the specific version of WebEngine you are using (which will be much older). I don't know if PyQt6/Qt6 uses a different version, but it might be worth giving it a try. I would suggest creating a [venv](https://docs.python.org/3/library/venv.html) and installing it via pip. – ekhumoro Feb 06 '22 at 19:22
  • I tried venv but again facing the same error . Looks like I'm facing issues with permissions . Any idea how to fix them . @ekhumoro ```[27472:11156:0207/172637.330:ERROR:cache_util_win.cc(21)] Unable to move the cache: Access is denied. (0x5) [27472:11156:0207/172637.330:ERROR:cache_util.cc(141)] Unable to move cache folder C:\Users\nirmal\AppData\Local\python\cache\QtWebEngine\Default\Cache to C:\Users\nirmal\AppData\Local\python\cache\QtWebEngine\Default\old_Cache_000 [27472:11156:0207/172637.331:ERROR:disk_cache.cc(178)] Unable to create cache ``` – Nirmal Kumar Feb 07 '22 at 12:00
  • I don't think those messages are relevant. I sometimes see similar messages, but it doesn't affect loading urls. If you want to solve this, you will have do some creative debugging yourself. Try using `setHtml()` to see if it's possible to at least *render* a web-page; try loading a local file, rather than an internet url; etc... – ekhumoro Feb 07 '22 at 18:34
  • Possible duplicate: https://stackoverflow.com/questions/72131093/pyqt5-qwebengineview-doesnt-load-url – Carlos May 18 '22 at 15:27

4 Answers4

2

I had the exact same issue after upgrading from Ubuntu 20.04 to 22.04. This is how I solved it after hours of trial and error:

First, I checked with pip3 list which PyQt5 packages are installed and removed every single one of them (using pip3 uninstall ...,especially PyQt5-Qt5) and all of the PyQtWebEngine packages. Then, I installed PyQt5 version 5.15.6 and the webengine like this (the second is basically according to Carlos ):

     pip3 install PyQt5-Qt5==5.15.6
     sudo apt-get install -y python3-pyqt5.qtwebengine 

This worked, at least for me. Hope it helps someone else...

  • 1
    Comments seem to suggest that the issue is specific to ubuntu, but it is not. It is also present in Manjaro and probably in arch. When PyQtWebEngine is installed via pip in a virtual environment it does not work. Seen with `retext` – callegar Jun 28 '22 at 18:09
  • this solved my issue, thanks a lot! btw I didn't have 5.15.6 but 5.16.2 instead, and it works well too. – Cagri Sep 19 '22 at 21:53
  • it helped me to resolve the same problem on Linux Mint 21 (based on Ubuntu 22.04) – furas Sep 27 '22 at 21:15
1

Try running QApplication without the sandbox as suggested here. But beware of the security implications.

app = QApplication(sys.argv + ['--no-sandbox'])
MiaPlan.de
  • 102
  • 8
0
PyQt5==5.15.9
PyQt5-Qt5==5.15.2
PyQt5-sip==12.11.1
PyQt5WebEngine==5.15.6
PyQtWebEngine-Qt5==5.15.2.

I am experiencing this same issue in PyQt5 if as been occurring for week, I have finally exhausted all available knowledge on PyQt5, one final solution is to try downgrading the versions of PyQt5, probably this issue is happening because of a bug from the library and not the programmer.

-2

web = QWebEngineView( widget name ) # You will write the name of the widget you created here

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 18 '22 at 08:09