How can I create a directly-executable cross-platform GUI app using Python?
threadspeed
Posted on May 22, 2020
The Python programming language works on many platforms including Microsoft Windows, Apple Mac OS X, many Linux distributions other systems.
This article consists of two parts:
- GUI module - how to create a desktop interface with Python
- Python to Executable - turn a Python program into an executable
The hardest part is learn Python, how to use a GUI module. To create an executable, there are several command line tools.
GUI module
The first thing you will need is a GUI module. Of course, there are many GUI modules for Python. The most commonly used GUI modules are:
- Tkinter - this module is based on the old Tk GUI toolkit. It is the default GUI library for python and it is free for commercial projects. Tk is rather limited with the number of widgets and has an old design.
- PyQt - Python bindings for the Qt framework. It's free (gpl) but not for commercial products. Qt comes with many widgets and features and is under continuous development. If you are new to PyQt, I recommend this course & book.
- PyGTK, a wrapper on the GTK toolkit. The gnome (gtk) desktop environment is an option on Linux systems.
Python is interpreted
Strictly speaking, you don't have to compile python for Mac/Windows/Linux because it is an interpreted language.
That means that if you have the Python interpreter installed on the platform and the required modules, you can run the program.
Python is installed on every Linux, Mac and Windows OS (I think) by default now. So all you need is have the non-standard modules installed if you use them.
However, your end-users may not be familiar with Python and other installing modules, so you may want to create an executable and an installer.
It is possible to build executables with the python interpreter, which we will discuss in the next section.
Create executable
After you made your GUI program in Python, you can convert it into a standalone executable. There are several tools that can do this, there is more than one way to do this.
Cross platform, all platforms
- PyInstaller - PyInstaller freezes Python apps into stand-alone executables for Windows, Linux, Mac OS X, FreeBSD, Solaris and AIX. It supports Python 2.7 and Python 3.3, 3.4, 3.5 and 3.6.
First install it with the pip package manager:
pip install pyinstaller
Then run pyinstaller in your programs folder:
pyinstaller file.py
- fbs - package Python apps that use PyQt. See Python PyQt to executable. fbs is not free for commercial use, but for non-commercial use it's free. It comes with setup program for your end-users.
Windows executable
- py2exe - converts your Python program to a windows executable. It's only for building executables on Windows, you can't build a Windows executable from Linux or Mac OS X.
Linux executable
- Freeze - works like py2exe but for the Linux platform
python freeze.py hello.py
Mac executable
- py2app - create Mac OS executables from Python. py2app is similar in purpose and design to py2exe for Windows.
Posted on May 22, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.