macOS

When packaging for macOS, cx_freeze may work for you. However, there is another alternative named py2app, which we will take a look at now.

Ensure you have the tkedit.py file described in the Windows section earlier, then install py2app into our virtual environment using pip. We will need version 0.13, since later versions do not support Tkinter properly:

$ source env/bin/activate
$ pip install py2app==0.13

With py2app installed, you can go ahead and let it generate a setup.py file using its setup tools:

$ py2applet --make-setup tkedit.py

This should overwrite your setup.py file with a new one. We will need to add our PyYAML dependency to it, so it looks like so:

"""
This is a setup.py script generated by py2applet

Usage:
python setup.py py2app
"""

from setuptools import setup

APP = ['tkedit.py']
DATA_FILES = []
OPTIONS = {'includes': ['PyYAML']}

setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)

With this taken care of, we can now install our dependencies and then execute the py2app command:

$ pip install PyYAML
$ python3 setup.py py2app

This should create two new folders for you, named build and dist. Your binary will be in the dist folder. You can run it by referencing it from the terminal, a:

$ ./dist/tkedit.app/Contents/MacOS/tkedit

If your editor pops up, congratulations! You have now created a macOS binary.

That covers everything for building packaged binaries. You hopefully should now be ready to port over your Tkinter GUI applications to distribute to the rest of the world. Of course, the more complicated the application, the more steps will be involved in getting it packaged; so, some in-depth reading of packaging Python applications is recommended. The official guide can be found at https://docs.python.org/3/distutils/setupscript.html

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset