【问题标题】:ImportError: cannot import name 'QtWebKitWidgets' from 'PyQt5' [duplicate]ImportError:无法从“PyQt5”导入名称“QtWebKitWidgets”[重复]
【发布时间】:2021-01-01 08:33:35
【问题描述】:

我使用 Qt Designer 在 Qt 上创建了一个窗口,当我启动该应用程序时 - 我得到了 ImportError。感觉就像那个库没有安装在我的系统中。但预览在 Qt Designer 中有效。

设计文件完整代码:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'map.ui'
#
# Created by: PyQt5 UI code generator 5.15.0
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(576, 616)
        self.horizontalLayout = QtWidgets.QHBoxLayout(Form)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.webView = QtWebEngineWidgets.QWebView(Form)
        self.webView.setUrl(QtCore.QUrl("https://www.openstreetmap.org/"))
        self.webView.setRenderHints(QtGui.QPainter.Antialiasing|QtGui.QPainter.SmoothPixmapTransform|QtGui.QPainter.TextAntialiasing)
        self.webView.setObjectName("webView")
        self.horizontalLayout.addWidget(self.webView)

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "VasMaps"))
        
from PyQt5 import QtWebEngineWidgets

错误日志:

Traceback (most recent call last):
  File "Qt/map.py", line 31, in <module>
    from PyQt5 import QtWebEngineWidgets
ImportError: /lib/x86_64-linux-gnu/libQt5Core.so.5: version `Qt_5.15' not found (required by /usr/local/lib/python3.8/dist-packages/PyQt5/QtWebEngineWidgets.abi3.so)

PyQtWebEngine 包是通过 pip 安装的。

【问题讨论】:

    标签: python-3.x pyqt5 qwebkit


    【解决方案1】:

    QtWebKit 在 5.6 版本之后已经被移除。

    您可以使用:

    from PyQt5 import QtWebEngineWidgets
    

    【讨论】:

      猜你喜欢
      • 2019-09-27
      • 2016-10-19
      • 2015-03-01
      • 1970-01-01
      • 2019-05-27
      • 2021-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多