Python 无法在 PyQt5 中导入 QtWebKitWidgets
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37876987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot import QtWebKitWidgets in PyQt5
提问by Peter Bingham
I've recently upgraded PyQt5 from 5.5.1 to 5.6.0 using the Windows 32-bit installer here: https://www.riverbankcomputing.com/software/pyqt/download5. I've also upgraded my python from 3.4 to 3.5.
我最近使用 Windows 32 位安装程序将 PyQt5 从 5.5.1 升级到 5.6.0:https://www.riverbankcomputing.com/software/pyqt/download5 。我还将我的 python 从 3.4 升级到 3.5。
When I run my old code (which used to work) with the latest version I get an exception:
当我使用最新版本运行旧代码(曾经可以工作)时,出现异常:
from PyQt5.QtWebKitWidgets import *
ImportError: No module named 'PyQt5.QtWebKitWidgets'
All of my QT calls in my python occur consecutively and are (and I know I shouldn't be importing * but that's beside the issue here I think):
我在 python 中的所有 QT 调用都是连续发生的(我知道我不应该导入 * 但我认为这是这里的问题之外):
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebKitWidgets import *
So the QtCore, QtGui and QtWidgets imports are all OK.
所以 QtCore、QtGui 和 QtWidgets 导入都没有问题。
Also, when I search the source for QtWebKitWidgets there appears several references to this module.
此外,当我搜索 QtWebKitWidgets 的源时,会出现对该模块的多个引用。
Finally my python path looks like:
最后我的python路径看起来像:
C:\PYTHON35;C:\PYTHON35\DLLs;C:\PYTHON35\LIB;C:\PYTHON35\LIB\LIB-TK;
and environment path:
和环境路径:
C:\Python35\Lib\site-packages\PyQt5;C:\Python35;C:\Python35\Lib;C:\Python35\Lib\site-packages;C:\Python35\Scripts ....
回答by IAmInPLS
QtWebKit
got deprecated upstream in Qt 5.5 and removed in 5.6.
QtWebKit
在 Qt 5.5 上游弃用并在 5.6 中删除。
You may want to switch to PyQt5.QtWebEngineWidgets:
你可能想切换到PyQt5.QtWebEngineWidgets:
This supercedes the QtWebKit module and provides better and up-to-date support for HTML, CSS and JavaScript features
这取代了 QtWebKit 模块,并为 HTML、CSS 和 JavaScript 功能提供了更好和最新的支持
回答by Spounka
I was trying to run qutebrowser and it had the same error, the answer is simple, the packages changed. You have two solutions:
我试图运行 qtebrowser 并且它有同样的错误,答案很简单,包改变了。您有两种解决方案:
1)
1)
pip install PyQtWebEngine
2)
2)
pip install PyQt5==5.11.3
Hope this helps any future problems
希望这有助于任何未来的问题
回答by Istiyak
In PyQt5 "QtWebKitWidgets"is Deprecated. I just replace this line
在 PyQt5 中,“QtWebKitWidgets”已弃用。我只是替换这一行
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
from PyQt5.QtWebKit import QWebSettings
With this code:
使用此代码:
from PyQt5.QtWebEngineWidgets import QWebEngineView as QWebView,QWebEnginePage as QWebPage
from PyQt5.QtWebEngineWidgets import QWebEngineSettings as QWebSettings
回答by SilverRayX
In PyQt5 "QtWebKitWidgets"is no longer available. Instead it is replaced with "QtWebEngineWidgets".So you have to make this change in your code.
在 PyQt5 中,“QtWebKitWidgets”不再可用。相反,它被替换为“QtWebEngineWidgets”。因此,您必须在代码中进行此更改。
For more information: http://doc.qt.io/qt-5/qtwebenginewidgets-qtwebkitportingguide.html
更多信息:http: //doc.qt.io/qt-5/qtwebenginewidgets-qtwebkitportingguide.html
回答by Sid
If you reallywant to use PyQt5.QtWebKitWidgets
, you could run this from the command line:
如果你真的想使用PyQt5.QtWebKitWidgets
,你可以从命令行运行它:
pip install PyQtWebKit
and let it do what it does.
让它做它该做的。