24

我想从 python 包创建一个 mac osx 应用程序,然后将其放入磁盘映像中。

因为我从包中加载了一些资源,所以包不应该驻留在 zip 文件中。

生成的磁盘映像应显示背景图片以“拖到此处 -> 应用程序”进行安装。

4

1 回答 1

7

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.

$ 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.

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.

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.

I know these aren't the clearest, simplest or most detailed instructions out there, but I hope somebody may find them useful.

于 2008-09-22T19:19:30.207 回答