如何编译包含 .kv 文件和其他资源文件的 .py 文件

How to compile a .py file which has a .kv file and other resource files

我用 python 和 Kivy 编写了一个应用程序,它有一个 main.py 和 main.kv 文件以及其他资源文件,如图像和文本文件。当我在 windows 7 上用 PyInstaller.exe 编译它们时,我不知道后台发生了什么。每次编译时,.exe 文件都会崩溃并出现不同的错误。

所以我希望有人阐明我将如何在我的 main.py 中获取所有文件,即编译的图像和文本文件。

我在命令行中尝试的命令是:

PyInstaller.exe --onefile --icon=myicon.png main.py

在你第一次运行Pyinstaller之后,它应该已经创建了一个main.spec文件。您可以编辑 main.spec 文件以添加您的应用所需的任何其他资源(除了 Pyinstaller 检测到的资源)。然后你可以 运行 Pyinstaller 使用简单的命令:

pyinstaller main.spec

请注意,当您提供规格文件参数时,Pyinstaller 的大多数选项都无效(所有信息都应在规格文件中)。有关详细信息,请参阅 Pyinstaller docs