How to create a Mac OS X app with Python?

前端 未结 11 1487
清酒与你
清酒与你 2020-12-12 18:07

I want to create a GUI application which should work on Windows and Mac. For this I\'ve chosen Python.

The problem is on Mac OS X.

There are 2 tools

相关标签:
11条回答
  • 2020-12-12 18:47

    2: You can't "convert" it, but you can move the executable to App.app/Contents/MacOS/something in a .app file, with CFBundleExecutable set to "something". This would not generally be recommended.

    0 讨论(0)
  • 2020-12-12 18:48

    Automator was already mentioned as a quick and simple solution for Pythons scripts that are contained in a single file, but since the Automator UI has so many options, and it is not obvious how to actually do it, I'll provide step-by-step instructions (verified to work on Yosemite):

    1. In Automator select File > New and pick Application as document type.
    2. Next, make sure Actions tab is selected on the left, and then in the search box type run. Among other options you'll see Run Shell Script — doubleclick it, and an editor window will appear in the right panel.
    3. From the Shell dropdown menu select /usr/bin/python.
    4. Paste your Python code into the edit window and then pick File > Save.

    By default, the app will be saved under $HOME/Applications and will appear in Spotlight.

    If you want to be able to set your own icon and have some fancy features, like task bar icons with a menu, log windows etc, then have a look at Platypus — an open-source app for creating MacOS native bundles.

    0 讨论(0)
  • 2020-12-12 18:50

    Having used py2exe for windows users so they wouldn't have to deal with library versions, I've torn apart the compiled programs, they include the python bytecode files. While you can make it a violation of the license to look inside those, the fact is that if a computer can execute them, I can read them. It is possible to compile python programs with gcc, via a C preprocessor (try looking for 2c.py on google), I don't know if any of them support GCC. Again, you don't gain any security through using them, but you can get a significant speed improvement.

    0 讨论(0)
  • 2020-12-12 18:50

    cxFreeze is best solution available, first create your program or application using python and than make setup file for your application, and than build the app using build command python setup.py build, according to your requirement you need to make some changes.

    0 讨论(0)
  • 2020-12-12 18:54

    How to configure py2app to include the source code in the executable, so the final users will not have access to my program?

    Unless you very seriously hack the python interpreter (and include the mangled version) there is no really good way to hide the source from a moderately skilled and determined user. I strongly believe this is true on Windows also. Basically, whether you include true source or bytecode, a pretty clean version of the source can be recovered. More importantly, in my opinion, unless you include the actual source code (as opposed to bytecode, you will introduce a possible dependency on the interpreter version).

    How to convert UNIX executable to Mac ".app" ?

    What do you mean by a UNIX executable? A Darwin (OS X) binary [which isn't actually UNIX]? That can be done using the kinds of tools you already mentioned, but it must be done carefully to avoid library dependencies.

    If all you want it a simple wrapper to put a command-line binary into a window, it's pretty easy to accomplish and the free XCode suite has several examples that would serve (depending on what output you wan to deliver, if any).

    Is there a way to compile Python code with GCC ?

    GCC does not compile Python. It's a different language (although there tools in the gcc family rthat support multiple language front-ends, but not Python). There are tools that attempt to translate Python into C, and then you can compile that into a true binary, but this only works for programs that avoid certain types of construct, and the process (and restrictions) need to apply your libraries as well.
    One project to allow this is Cython. It works well for some types of code, mostly numerical code, but it is not trivial to install and exploit, very especially if you want to produce something that runs on multiple different computers.

    In Windows it's easy, I created an "exe" file from Python code and it works. Is it possible to create a single file "app" for Mac ?

    I would have to say I am skeptical -- very skeptical -- about this. Just like the OS X case, the exe almost certainly has the source code trivially accessible within it.

    One fairly easy trick is to encrypt the source code and then decrypt it on the fly, but this seems to me like more trouble than it's worth.

    0 讨论(0)
提交回复
热议问题