开发者

What is the proper way to make a Python frozen binaries for OSX that can accept arguments?

I've made a .app bundle from a python script using py2app. The issue is twofold:

  1. Argument emulation doesn't appear to work correctly because it doesn't accept the arguments that work on the original python script.

  2. The .app bundle format needs to be opened by "open". "open" only supports passing arguments from OSX 10.6 and on, and I need support for earlier OSX versions.

Whats the proper w开发者_JAVA技巧ay to make a frozen binary for OSX that can accept command line arguments?


In general, OS X app bundles are not designed to be started from a command line and passed arguments from a command line (as you note, OS X 10.6 added some support for this). The standard mechanism for passing files to an app is through Apple Events; this is used for the Finder's Open command of a document file with a type handled by the app or when a file is dropped on the app's icon in the Dock. py2app is designed to package applications that will be used like standard Mac GUI applications, in particular using the launch protocol and receiving files through Apple Events. It is not designed to produce command-line utilities. If the latter is what you are packaging, simply use the normal Distutils method of packaging. Or, if your script consists of only one file, you can make it a standalone shebang script as described here.

Also note that while running as a full-fledged app is necessary on OS X to use certain GUI interfaces, Python itself on OS X is normally installed in a framework and run from within a Python.app bundle installed inside the framework. (This is true for the Apple-supplied Pythons, those installed by python.org installers, and MacPorts installed Pythons.) When scripts are run by one of these framework Pythons, they are recognized as GUI apps by OS X without the need to build their own app bundles.


Use pyinstaller it can easily create linux-like command line binary executables for OS X. It also can do it for linux and Windows OSes.

I've used both py2app and pyinstaller to do OS X executables and as for me pyinstaller is better and easier to configure. However py2app also can handle arguments, even it create app bundles. So think you have just wrong building settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜