ImportError: DLL load failed while importing QtWebKit: Le module spécifié est introuvable

Viewed 128

the code :

  • I don't know why it doesn't run at execution time, knowing that I downloaded all the libraries needed by the program

     from PyQt5.QtCore import QUrl
     from PyQt5.QtWebKit import QWebSettings
     from PyQt5.QtWebKitWidgets import QWebView, QWebInspector
     from PyQt5.QtWidgets import QApplication, QSplitter, QVBoxLayout, QWidget
    
    
    
     class Window(QWidget):
         def __init__(self, parent=None):
             QWidget.__init__(self, parent=parent)
             self.view = QWebView(self)
             self.view.settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
             self.inspector = QWebInspector()
             self.inspector.setPage(self.view.page())
             self.inspector.show()
             self.splitter = QSplitter(self)
             self.splitter.addWidget(self.view)
             self.splitter.addWidget(self.inspector)
             layout = QVBoxLayout(self)
             layout.addWidget(self.splitter)
    
     if __name__ == '__main__':
         import sys
         app = QApplication(sys.argv)
         window = Window()
         window.view.load(QUrl('http://www.google.com'))
         window.show()
         sys.exit(app.exec_())
    

    after excute :

     Traceback (most recent call last):
       File "c:\Users\pc\Desktop\tempCodeRunnerFile.py", line 2, in <module>
         from PyQt5.QtWebKit import QWebSettings
     ImportError: DLL load failed while importing QtWebKit: Le module spécifié est introuvable.
    

I don't know why it doesn't run at execution time, knowing that I downloaded all the libraries needed by the program

library 1 :

pip install PyQtWebEngine

library 2 :

pip install PyQt5

Is there a solution to this problem ??

1 Answers

The code you sample uses QtWebKit, not Qt WebEngine. If you have installed pyqtwebengine then use the following code:

from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QApplication, QSplitter, QVBoxLayout, QWidget
from PyQt5.QtWebEngineWidgets import QWebEngineView


class Window(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent=parent)
        self.view = QWebEngineView()
        self.inspector = QWebEngineView()
        self.view.page().setDevToolsPage(self.inspector.page())
        self.splitter = QSplitter(self)
        self.splitter.addWidget(self.view)
        self.splitter.addWidget(self.inspector)
        layout = QVBoxLayout(self)
        layout.addWidget(self.splitter)


if __name__ == "__main__":
    import sys

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