Problema de Python Pyinstaller MSYS con PyQtWebKit

0

web_browser.py

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

# Form implementation generated from reading ui file 'web_browser.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# 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_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(779, 257)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setSpacing(0)
        self.verticalLayout.setObjectName("verticalLayout")
        MainWindow.setCentralWidget(self.centralwidget)

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

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

web_browser_main.py

from web_browser import *
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import QUrl
from PyQt5.QtWebKitWidgets import QWebView , QWebPage
import sys
class TestBrowserCode:
    def __init__(self):
        self.app = QtWidgets.QApplication(sys.argv)
        self.mainWindow = QtWidgets.QMainWindow()
        self.main_ui = Ui_MainWindow()
        self.main_ui.setupUi(self.mainWindow)
        self.mainWindow.showMaximized()
        
        self.open_google()
        
        sys.exit(self.app.exec_())
        
    def open_google(self):
        self.google_url = 'http://www.google.com'
        
        self.main_ui.chat_browser = QWebView()
        self.main_ui.chat_page = QWebPage()
        self.main_ui.chat_browser.setPage(self.main_ui.chat_page)
        self.main_ui.chat_browser.setUrl(QUrl(self.google_url))
        
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)


        self.main_ui.chat_browser.setMinimumSize(QtCore.QSize(0, 398))
        self.main_ui.chat_browser.setMaximumSize(QtCore.QSize(16777215, 398))
        
        
        self.main_ui.chat_browser.setSizePolicy(sizePolicy)
        self.main_ui.chat_browser.setStyleSheet("background-color:white;border:1px solid #dadada;")
        
        self.main_ui.verticalLayout.addWidget(self.main_ui.chat_browser)
        
        self.main_ui.chat_browser.show()

program = TestBrowserCode()
  1. Ejecute el código desde la fuente:
Χρήστος@Chris-pc MINGW64 /c/python/scripts/Papinhio player/notes
$ python web_browser_main.py

(El sitio se muestra correctamente)

  1. Haga un archivo .exe ( resultado completo aquí )
Traceback (most recent call last):
  File "C:/Python/Scripts/Papinhio player/notes/web_browser_main.py", line 4, in
 
    from PyQt5.QtWebKitWidgets import QWebView , QWebPage
  File "", line 991, in _find_and_load
  File "", line 975, in _find_and_load_unlocked
  File "", line 657, in _load_unlocked
  File "", line 556, in module_from_spec
  File "", line 1101, in create_module
  File "", line 219, in _call_with_frames_removed
  File "", line 991, in _find_and_load
  File "", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'PyQt5.QtWebKit'
[17208] Failed to execute script web_browser_main

Importación de error de resultado PyQt5.QtWebKitWidgets

Todo eso dentro de la consola msys2 mingw64. ¿Cómo puedo compilar los archivos anteriores?

1
pyinstaller --onefile --hidden-import PyQt5.QtWebKit web_browser_main.py

El código superior incluye el módulo QtWebKit que falta. Sugiero usar --onedir en lugar de --OneFile porque creo que el exe de salida es más estable. (Tuve un error de tiempo de ejecución de Segmentfault después de algunos segundos en una aplicación como la aplicación web_browser_main)

Funciona ahora !!!

2
  • Explique qué hace el código y cómo lo hace. 24 abr a las 15:39
  • @ M-Chen-3 lo hizo
    Chris P
    24 abr a las 15:47