I keep getting this error:
ImportError: cannot import name 'QWebView'
...for this bit of code:
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebPage
-I'm on a Mac running High Sierra 10.13.3
-I installed Python 3.6.4
-Installed PyQt5 (did this several times, including using HomeBrew)
I'm pretty sure everything is installed correctly cause when I run python3 -m pip install PyQt5
it tells me Requirement already satisfied
:
MacBook-Pro-3:~ ericj36$ python3 -m pip install PyQt5
Requirement already satisfied: PyQt5 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
Requirement already satisfied: sip<4.20,>=4.19.4 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from PyQt5)
The full error I get when I try to run my code is:
...line 4, in <module>
from PyQt5.QtWebEngineWidgets import QWebView
ImportError: cannot import name 'QWebView'
So what could be happening here? What am I doing wrong? (I'm new to Python - but not to development.)
Any help would be greatly appreciated.
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
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.