Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Mac OS X app with Python?

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 to generate an ".app" for Mac: py2app and pyinstaller.

  1. py2app is pretty good, but it adds the source code in the package. I don't want to share the code with the final users.
  2. Pyinstaller generates UNIX executable, so how to run it on Mac? I created a bundles with this executable, but the resulted ".app" is not working.

The questions are:

  1. How to configure py2app to include the source code in the executable, so the final users will not have access to my program?
  2. How to convert UNIX executable to Mac ".app" ?
  3. Is there a way to compile Python code with GCC ?
  4. 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 ?

P.S. I use two computers (Windows and for Mac), Python 2.7, wxPython, py2exe, py2app and pyinstaller.

Also, I have checked out these sites:

  • http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html
  • http://www.pyinstaller.org/export/develop/project/doc/Manual.html?format=raw
  • http://www.pyinstaller.org/wiki/Features/MacOsCompatibility
  • http://www.stackoverflow.com/questions/2933/an-executable-python-app
like image 687
Cristian Ciocău Avatar asked Aug 31 '11 18:08

Cristian Ciocău


People also ask

Can you create a Mac app with Python?

py2app is a Python setuptools command which will allow you to make standalone Mac OS X application bundles and plugins from Python scripts. py2app is similar in purpose and design to py2exe for Windows. NOTE: py2app must be used on macOS to build applications, it cannot create Mac applications on other platforms.

Does Mac OS X come with Python?

Python comes pre-installed on Mac OS X so it is easy to start using. However, to take advantage of the latest versions of Python, you will need to download and install newer versions alongside the system ones. The easiest way to do that is to install one of the binary installers for OS X from the Python Download page.


1 Answers

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.

like image 89
GregD Avatar answered Oct 23 '22 14:10

GregD