kdqfi.over-blog.com/
7 Janvier 2021
In this tutorial we'll be using py2app to create a standalone OSX application from a Python 2 or 3 source code with asimple Tkinter user interface.
'py2app is a Python setuptools command which will allow you to make standalone application bundles and plugins from Python scripts. py2app is similar in purpose and design to py2exe for Windows.'

Python executable mac (8) 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. Python for Mac OS X 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. Webarchive to pdf mac.
Relevant links about py2app:
This guide is loosely based on the official tutorial.Based on a Python file called Sandwich.py, we'll create an application called Sandwich.app.
The latest version of Mac OS X, High Sierra, comes with Python 2.7 out of the box. Before installing Python, you'll need to install a C compiler. Under Windows, choose Start ‣ Programs ‣ Python X.Y ‣ Python (command line). Once the interpreter is started, you type Python code at the prompt. For example, on my Linux system, I type the three Python statements shown below, and get the output as shown, to find out my prefix and exec-prefix.
Create a custom directory and create a virtualenv:
Now create a very simple Tkinter app with the filename Sandwich.py:

This little app will look like this:
The original version of py2app has a bug due to a newer version of ModuleGraph. Imade a fork of the project and fixed this bug on Github.Install it with pip like this:
setup.py filepy2app includes py2applet, a helper which generates a setup.py file for you: Fasttasks 2 46 – the troubleshooting appendicular.
This setup.py is a basic definition of the app:
If your application uses some data files, like a JSON, text files or images, you should include them in DATA_FILES. For example:
py2app builds the standalone application based on the definition in setup.py.
For testing and development, py2app provides an 'alias mode', which builds anapp with symbolic links to the development files:
This creates the following files and directories:
This is not a standalone application, and the applications built in alias mode are not portable to other machines!
The app built with alias mode simply references the original code files, so any changes you make to the original Sandwich.py file are instantly available on the next app start.
The resulting development app in dist/Sandwich.app can be opened just like any other .app with the Finderor the open command ($ open dist/Sandwich.app). To run your application directly from the Terminalyou can just run:
Nuns steal 500k. When everything is tested you can produce a build for deployment with a calling python setup.py py2app. Make sure that any old build and dist directories are removed:
This will assemble your application as dist/Sandwich.app. Since this application is self-contained, you will have to run the py2app command again any time you change any source code, data files, options, etc.
The original py2app has a bug which would display 'AttributeError: 'ModuleGraph' object has no attribute 'scan_code'' or load_module. If you encounter this error, takea look at this StackOverflow thread or use my fork of py2app.
The easiest way to wrap your application up for distribution at this point is simply to right-click the application from Finder and choose 'Create Archive'.
Simply add 'iconfile': 'youricon.icns' to the OPTIONS dict:
You can find free icons in icns format around the web (eg. on IconFinder or freepik).
You can tweak the application information and behaviour with modificationsto the Info.plist. The most complete reference for the keys available is Apple's Runtime Configuration Guidelines.
Here is an example with more modifications:
With these settings, the app will have the following infos:
If you have suggestions, feedback or ideas, please reach out to me @metachris.
