macos 如何从 python 包创建 osx 应用程序/dmg?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/116657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you create an osx application/dmg from a python package?
提问by Florian B?sch
I want to create a mac osx application from python package and then put it in a disk image.
我想从 python 包创建一个 mac osx 应用程序,然后将其放入磁盘映像中。
Because I load some resources out of the package, the package should notreside in a zip file.
因为我加载一些资源出来的包,包应该不会驻留在一个zip文件。
The resulting disk image should display the background picture to "drag here -> applications" for installation.
生成的磁盘映像应显示背景图片以“拖到此处-> 应用程序”进行安装。
回答by Facebook Staff are Complicit
I don't know the correct way to do it, but this manual method is the approach I've used for simple scripts which seems to have preformed suitably.
我不知道正确的方法,但这种手动方法是我用于简单脚本的方法,这些脚本似乎已经适当地执行了。
I'll assume that whatever directory I'm in, the Python files for my program are in the relative src/
directory, and that the file I want to execute (which has the proper shebang and execute permissions) is named main.py
.
我将假设无论我在src/
哪个目录中,我的程序的 Python 文件都在相对目录中,并且我要执行的文件(具有适当的 shebang 和执行权限)名为main.py
.
$ mkdir -p MyApplication.app/Contents/MacOS $ mv src/* MyApplication.app/Contents/MacOS $ cd MyApplication.app/Contents/MacOS $ mv main.py MyApplication
At this point we have an application bundle which, as far as I know, should work on any Mac OS system with Python installed (which I think it has by default). It doesn't have an icon or anything, that requires adding some more metadata to the package which is unnecessary for my purposes and I'm not familiar with.
在这一点上,我们有一个应用程序包,据我所知,它应该可以在任何安装了 Python 的 Mac OS 系统上运行(我认为它在默认情况下有)。它没有图标或任何东西,需要向包添加更多元数据,这对于我的目的来说是不必要的,我也不熟悉。
To create the drag-and-drop installer is quite simple. Use Disk Utility to create a New Disk Image of approximately the size you require to store your application. Open it up, copy your application and an alias of /Applications
to the drive, then use View Options to position them as you want.
创建拖放安装程序非常简单。使用磁盘工具创建一个新的磁盘映像,其大小大约为您存储应用程序所需的大小。打开它,将您的应用程序和 的别名复制/Applications
到驱动器,然后使用“查看选项”根据需要定位它们。
The drag-and-drop message is just a background of the disk image, which you can also specify in View Options. I haven't done it before, but I'd assume that after you whip up an image in your editor of choice you could copy it over, set it as the background and then use chflags hidden
to prevent it from cluttering up your nice window.
拖放消息只是磁盘映像的背景,您也可以在“查看选项”中指定。我以前没有这样做过,但我假设在您在您选择的编辑器中制作图像后,您可以将其复制过来,将其设置为背景,然后使用chflags hidden
它来防止它弄乱您的漂亮窗口。
I know these aren't the clearest, simplest or most detailed instructions out there, but I hope somebody may find them useful.
我知道这些不是最清晰、最简单或最详细的说明,但我希望有人会发现它们有用。