简体   繁体   English

将 Kivy/Python 应用程序捆绑到一个易于安装的 Mac 应用程序文件中

[英]Bundling a Kivy/Python App into an easily installable .app file for mac

I have been writing a graphical data management app in Python/Kivy for MacOS, and when I am done, I would like the end user to be able to install it without touching the command line.我一直在用 Python/Kivy 为 MacOS 编写一个图形数据管理应用程序,当我完成后,我希望最终用户能够在不接触命令行的情况下安装它。 The computers that it is intended for already have python, but not Kivy.它适用的计算机已经有 python,但没有 Kivy。 I was wondering what the easiest approach would be, perhaps an installer that would just execute 'pip install kivy' in the command line, or a python file using the OS module that installs it, or maybe pyinstaller.我想知道最简单的方法是什么,也许是一个只在命令行中执行“pip install kivy”的安装程序,或者是使用安装它的 OS 模块的 python 文件,或者可能是 pyinstaller。 Thanks!谢谢!

This is actually mentioned in the Kivy documentation here .这实际上在此处的 Kivy 文档中提到。 Read more for customizing your install.阅读更多以定制您的安装。

Prerequisites先决条件

For a basic install, you first need to install PyInstaller and Cython.对于基本安装,您首先需要安装 PyInstaller 和 Cython。 Do this with pip3 install PyInstaller, Cython .使用pip3 install PyInstaller, Cython执行此操作。

Bugs错误

There is a bug in setuptools that causes PyInstaller to not work. setuptools 中有一个错误导致 PyInstaller 无法工作。 You need to have a version of setuptools less than 45.0.0 to work.您需要使用低于 45.0.0 的 setuptools 版本才能工作。 To do this, run the following command pip3 install --upgrade setuptools==44.1.1 .为此,请运行以下命令pip3 install --upgrade setuptools==44.1.1 Finally, you are ready to package最后,您准备好 package

Creating *.spec file创建 *.spec 文件

PyInstaller works off of a *.spec file. PyInstaller 使用 *.spec 文件。 To create this, as said by the Kivy documentation, run the following command:如 Kivy 文档所述,要创建它,请运行以下命令:

pyinstaller -y --clean --windowed --name <the name of the *.app> \
  --exclude-module _tkinter \
  --exclude-module Tkinter \
  --exclude-module enchant \
  --exclude-module twisted \
  /path/to/main/program.py

Remember to replace <the name of the *.app> with what you want the name of the *.app to be, and /path/to/main/program.py with the path to your main python program file.请记住将<the name of the *.app>替换为您希望 *.app 的名称,并将/path/to/main/program.py替换为您的主 python 程序文件的路径。 The path can be relative too.路径也可以是相对的。 This will take a bit, but will produce a file with an extension of a *.spec, which you will use to customize the app, create a directory called build , which you can delete, and create a directory called dist .这将花费一些时间,但会生成一个扩展名为 *.spec 的文件,您将使用它来自定义应用程序,创建一个名为build的目录,您可以将其删除,并创建一个名为dist的目录。 Inside the dist directory, you will find your application.dist目录中,您将找到您的应用程序。

Debugging调试

If when you open your app it immediately closes, you have an error.如果当你打开你的应用程序时它立即关闭,你有一个错误。 To find out what it is, find the app in Finder, right-click it, and select "Show Package Contents```. Go inside a folder called "Contents", then inside a folder called "MacOS", in which you will see a lot of files. Find a file with a little "exec" icon on it with the name of the *.app file. Double-click this. This will bring up a terminal window with errors and console output. Copy-paste the error into Google, which should help, and also feel free to comment it here, and I will try to check it out!要找出它是什么,在Finder中找到该应用程序,右键单击它,然后 select "Show Package Contents```. Go 文件夹内名为 "MacOS" 的文件夹"内容",然后您将在文件夹中看到很多文件。找到一个带有小“exec”图标的文件,其名称为 *.app 文件。双击它。这将打开一个带有错误的终端 window 和控制台 output。复制粘贴错误进入谷歌,这应该会有所帮助,也可以在这里发表评论,我会尝试检查出来!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM