python-3.x 导入错误:无法导入名称QWebEngineView

relj7zay  于 2023-02-14  发布在  Python
关注(0)|答案(1)|浏览(359)
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QWebEngineView

app = QApplication(sys.argv)
window = QMainWindow()
view = QWebEngineView()
view.load(QUrl("http://www.google.com"))
window.setCentralWidget(view)
window.show()
sys.exit(app.exec_())

这正是我在代码中遇到的错误:

Traceback (most recent call last):
  File "C:\Users\eymen\Desktop\qtweb.py", line 2, in <module>
    from PyQt5.QtWidgets import QApplication, QMainWindow, QWebEngineView
ImportError: cannot import name 'QWebEngineView' from 'PyQt5.QtWidgets' (C:\Users\eymen\AppData\Local\Programs\Python\Python311\Lib\site-packages\PyQt5\QtWidgets.pyd)

但我的pyqt5版本是最新的,我没有看到任何错误。我以为它与Python版本有关,但我不知道。Python版本:3.11.1备选库不能满足我的要求。

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QWebEngineView

app = QApplication(sys.argv)
window = QMainWindow()
view = QWebEngineView()
view.load(QUrl("http://www.google.com"))
window.setCentralWidget(view)
window.show()
sys.exit(app.exec_())

我尝试了这段代码,但当它应该google.com在python窗口中显示www.example.com时,它给出了错误,并说QWebEngineView库不受支持

smdncfj3

smdncfj31#

你需要使用

from PyQt5.QtWebEngineWidgets import QWebEngineView

代码:

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QUrl

app = QApplication(sys.argv)
window = QMainWindow()
view = QWebEngineView()
view.load(QUrl("http://www.google.com"))
window.setCentralWidget(view)
window.show()
sys.exit(app.exec_())

相关问题