使用PyInstaller打包的PySide6应用程序未启动且无错误

2024-09-25 00:26:42 发布

您现在位置:Python中文网/ 问答频道 /正文

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

  • Python病毒
  • 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的问题不是我遇到的问题。正如我在下面的评论中提到的,我已经解决了这个特殊的错误


Tags: frompyimportself应用程序sysloaderwindow
1条回答
网友
1楼 · 发布于 2024-09-25 00:26:42

这里是一个linkto docs,您可以在其中找到一个表,该表总结了平台对不同打包工具的支持

Table: support for packaging tools

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

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

Compiling Python applications is complicated work, and many Qt for Python users are always looking for ways to deploy standalone binaries from their Python applications. This is why we created all the tools tutorials in our documentation.

So far, all the solutions are based on the idea of packaging the Python code, and distributing it, but none of them was focused on compiling the code, here is where Nuitka ticks all the boxes.

We love Nuitka, and we are certain you will love it too!

If this name is new to you, in a nutshell we can tell you that it’s a Python compiler written in Python, you can read more in their website.

We are thankful for all the time Kay Hayen took to make Nuitka compatible with PySide 6.1, and we are looking forward to hearing from your own experiences what we could improve from this joint effort.

我想你可以试试它而不是PyInstaller

相关问题 更多 >