【问题标题】:PySide6 app packaged with PyInstaller not starting with no errors使用 PyInstaller 打包的 PySide6 应用程序启动时没有错误
【发布时间】:2021-08-07 09:10:01
【问题描述】:

我正在尝试创建一个独立的 PySide6 应用程序可执行文件。我的设置是:

  • Python venv
  • Python 3.9
  • PySide 6.1.0
  • Pyinstaller 4.3
  • 64 位 Windows 10

这是一个像这样的简单脚本:

from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import (QWidget, QApplication)
import sys

class Window(QWidget):

    def __init__(self):
        super(Window, self).__init__()
        self.setWindowTitle("hellooo")

if __name__== "__main__":
    app = QApplication([])
    win = Window()
    win.show()
    sys.exit(app.exec_())

应用程序作为脚本运行良好。但是当我像这样使用 Pyinstaller 将其转换为 exe 时:

pyinstaller --onefile --debug=all --windowed --console hello.py

应用程序不会立即启动并退出,并且没有显示任何有意义的错误。控制台输出是这样的:


[12384] LOADER: Setting sys.argv
[12384] LOADER: setting sys._MEIPASS
[12384] LOADER: importing modules from CArchive
[12384] LOADER: extracted struct
[12384] LOADER: callfunction returned...
[12384] LOADER: extracted pyimod01_os_path
[12384] LOADER: callfunction returned...
[12384] LOADER: extracted pyimod02_archive
[12384] LOADER: callfunction returned...
[12384] LOADER: extracted pyimod03_importers
[12384] LOADER: callfunction returned...
[12384] LOADER: Installing PYZ archive with Python modules.
[12384] LOADER: PYZ archive: PYZ-00.pyz
[12384] LOADER: Running pyiboot01_bootstrap.py
[12384] LOADER: Running pyi_rth_multiprocessing.py
[12384] LOADER: Running pyi_rth_certifi.py
[12384] LOADER: Running main_window.py
[408] LOADER: Back to parent (RC: -1073741819)
[408] LOADER: Doing cleanup

我的实际应用比这更复杂。我只是使用上面的示例来查看它是否可以作为 exe 工作,但两者都有相同的问题。

注意:我查看了本网站和其他地方的所有相关问题,但没有任何帮助。

注意:下面第一条评论中提到的关于 qt platform not found 的问题不是我遇到的问题。正如我在下面的评论中提到的那样,我已经解决了这个特定的错误。

【问题讨论】:

    标签: python pyinstaller pyside6


    【解决方案1】:

    这是一个link 文档,您可以在其中找到一个表格,该表格总结了不同打包工具的平台支持。

    Table: support for packaging tools

    根据该表,目前 Qt6 仅部分支持 PyInstaller。

    但是Qt官网有一个博客post,他们在里面写了Nuitka

    编译 Python 应用程序是一项复杂的工作,许多 Qt for Python 用户一直在寻找从他们的 Python 应用程序部署独立二进制文件的方法。这就是我们在文档中创建所有工具教程的原因。

    到目前为止,所有的解决方案都是基于打包 Python 代码并分发它的想法,但没有一个专注于编译代码,这里是 Nuitka 打勾所有框的地方。

    我们喜欢 Nuitka,我们相信您也会喜​​欢它!

    如果这个名字对你来说是新名字,简而言之,我们可以告诉你它是一个用 Python 编写的 Python 编译器,你可以在他们的网站上阅读更多内容。

    我们感谢 Kay Hayen 为使 Nuitka 与 PySide 6.1 兼容而付出的所有时间,我们期待从您的经验中听到我们可以从这项共同努力中改进的地方。

    我认为您可以尝试使用它来代替 PyInstaller。

    【讨论】:

    • 我正在寻找使用 PySide6 的 PyInstaller 修复程序,但切换到 Nuikta 几乎是开箱即用的。我用过这个命令行:python -m nuitka --standalone --enable-plugin=pyside6 main.py
    猜你喜欢
    • 2021-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 2015-09-24
    相关资源
    最近更新 更多