python开发macos程序,如何从python包创建osx应用程序/ dmg?

I want to create a mac osx application from python package and then put it in a disk image.

Because I load some resources out of the package, the package should not reside in a zip file.

The resulting disk image should display the background picture to "drag here -> applications" for installation.

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值