Building your own AppImages with appimagetool
Portable Packages
© Lead Image © kurhan, 123RF.com
AppImage packages are highly portable and don't require dependencies. A tool called appimagetool will bundle your Python application into a single AppImage executable.
AppImage [1] is a format for packaging applications on Linux so they can run on most distributions without installation or root permissions. Instead of scattering files across the system, an AppImage bundles the application's executable, libraries, icons, and other resources into a single, self-contained file. You can download it, make it executable, and run it directly, much like a portable app on Windows or a macOS .app bundle. Because it carries its dependencies with it, an AppImage avoids many of the compatibility issues that arise from differences between Linux distributions. It also leaves the host system untouched, because it doesn't require modifying system directories or package managers. An AppImage is therefore a convenient way to distribute software to a wide audience while keeping the user's environment clean and easy to maintain.
Turning a Python script into a portable Linux application might sound like a task reserved for seasoned developers, but with the right tools, it's surprisingly easy. In this article, I will walk through the transformation step by step, starting with PyInstaller to bundle code and dependencies into a single executable. From there, I'll introduce appimagetool, the utility that packages this executable into an AppImage. Throughout this guide, I will elucidate the AppImage creation workflow, detailing the rationale behind each procedural step. Upon completion, you will possess a comprehensive grasp of the methodology required to build an AppImage.
Setting Up Your Linux Environment
To get the most out of this article, you'll need a basic understanding of Python, because the starting point will be a Python script. You will also need Python installed on your system, along with pip to manage packages, and the ability to install additional tools such as PyInstaller. For preparing the Python script that will eventually become your AppImage, you will want a reliable and comfortable coding environment. A code editor such as Visual Studio Code (Figure 1) is a good choice, offering syntax highlighting, intelligent code completion, integrated terminal access, and built-in Git support. Working in an editor like VS Code makes it easier to write and debug your script, and it also helps you keep your project organized as you move from development to packaging. Because the process involves running commands for PyInstaller, and later appimagetool, having the terminal right inside your editor means you can write, test, and package your application without constantly switching between windows. This streamlined workflow is especially valuable when you are fine-tuning your code before locking it into a portable, distributable format.
Installing Visual Studio Code on Linux is straightforward, and you can choose the method that best fits your distribution and workflow. If you are on Ubuntu or another Debian-based system you can simply run
sudo snap install --classic code
in the terminal. For Fedora, CentOS, or RHEL, you can install it from Microsoft's yum repository, and Arch Linux users can find it in the community repository via pacman. Once installed, you can launch VS Code by typing code in the terminal or selecting it from your applications menu. For more details and alternative installation methods, check the official Visual Studio Code Linux setup guide [2].
For this project, you'll need a working Python environment before you can package anything with PyInstaller. On most modern Linux distributions, Python is either pre-installed or available through the system's package manager. If you're on Ubuntu or Debian, you can open a terminal and run
sudo apt update sudo apt install python3 python3-pip
Once Python is installed, verify it by running with
python3 --version pip3 --version
With Python ready, installing PyInstaller is straightforward because it is distributed via PyPI. Simply run
pip3 install pyinstaller
At this point, your system is equipped to take a Python script and turn it into a standalone executable.
Appimagetool is the command-line utility used to turn a prepared application directory into a fully functional AppImage. Think of it as the "final packaging" step: Once you have your application's executable and all its required resources arranged in the correct folder structure (usually called AppDir), appimagetool compresses and bundles everything into a single .AppImage file. This file can then run on most modern Linux distributions without installation or root access – and without worrying about missing dependencies.
Because it's part of the official AppImage project, appimagetool ensures your package follows the correct format and includes the necessary metadata, such as the desktop entry and icon, so that your AppImage integrates nicely with Linux desktops.
The easiest method to install appimagetool is to download the prebuilt binary directly from the appimagetool GitHub page [3] and place it in a folder included in the PATH.
Hello World
Before initiating the packaging and distribution workflow, it's practical to begin with a minimal yet illustrative Python script that will act as the foundational payload for the AppImage. This initial example is intentionally lightweight and non-production, essentially a stylized "Hello World" implementation with added character, serving as a controlled environment to demonstrate the bundling process without introducing unnecessary complexity.
The rationale for using a simplified, non-functional prototype is to isolate and emphasize the procedural aspects of application packaging. By abstracting away intricate business logic or advanced functionality, the focus remains squarely on the mechanics of converting a Python script into a portable, self-contained executable format. Listing 1 contains the script that I will use to create the final AppImage.
Listing 1
hw.py
import time
import random
def dramatic_countdown():
print("Initializing launch sequence...")
for i in range(3, 0, -1):
print(f"T-minus {i}...")
time.sleep(1)
print("Ignition!")
time.sleep(0.5)
print("? Launching Hello World Protocol...\n")
time.sleep(1)
def quirky_hello():
greetings = [
"Hello, World! ?",
"Greetings, Earthlings!",
"Hey there, digital wanderer!",
"Ahoy, terminal explorer!",
"Hello World... but make it fashion ?"
]
print(random.choice(greetings))
if __name__ == "__main__":
dramatic_countdown()
quirky_hello()
The script in Listing 1 begins by importing two standard libraries: time, which allows you to pause execution for dramatic effect, and random, which helps you choose a greeting from a list of quirky options.
The dramatic_countdown() function sets the stage. dramatic_countdown() prints a launch sequence message, counts down from 3 to 1 with a one-second pause between each number, and then simulates ignition and launch with a few well-timed print statements. The use of emojis adds a visual punch that makes the terminal output feel more alive.
Next, the quirky_hello() function selects a greeting from a list of five humorous and unconventional messages. Instead of the usual "Hello World," the user might be greeted with "Hey there, digital wanderer!". This randomness adds a layer of surprise and personality to each run.
The script uses the if __name__ == "__main__": block to call both functions in sequence, first the countdown, then the greeting (Figure 2).
Packaging the Script with PyInstaller
PyInstaller is a powerful tool that transforms Python scripts into standalone executables, making it possible to distribute your application without requiring users to install Python or any dependencies. It analyzes your code, detects all the libraries and modules it relies on, and bundles them together into a single package that can run on the target system, whether or not Python is installed.
One of PyInstaller's most compelling features is its ability to generate a one-file executable. This means that, instead of producing a folder full of files, it compresses everything (your code, the Python interpreter, and all required libraries) into a single binary. For developers, this simplifies distribution, reduces clutter, and gives users a clean, click-and-run experience.
Behind the scenes, PyInstaller creates a temporary directory when the executable is launched, extracts the bundled contents there, and runs the application as if it were installed normally. But to the user, it feels seamless. No setup, no configuration: just one file that does it all.
To create a one-file executable, open your terminal and navigate to the folder containing your script. Then run the following command:
pyinstaller --onefile hw.py
The --onefile option in PyInstaller instructs the build process to consolidate all components into a single executable binary. In the absence of this flag, PyInstaller defaults to generating a directory-based distribution, where the executable resides alongside its required shared libraries and auxiliary files. Upon completion, the output artifacts are placed within the dist directory. On Linux systems, the resulting binary will be named hw, whereas on Windows platforms, it appears as hw.exe. Make sure the file is executable and then launch it:
chmod +x hw ./hw
You should see the countdown, the rocket launch, and one of the quirky greetings delivered by a fully self-contained application. This one-file executable is exactly what I will wrap into an AppImage.
Although this approach simplifies distribution, it still requires compatible versions of certain system-level libraries (such as glibc and graphical libraries) on the target machine. Although the Python interpreter and your code are embedded, the executable does not fully isolate itself from the host environment, which can lead to compatibility issues if the system lacks the expected versions of required libraries. Portability is therefore limited, and it is generally recommended to build the executable on the same operating system and architecture as the intended deployment target. AppImages are designed to overcome this limitation.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Framework Laptop 13 Pro Competes with the Best
Framework has released what might be considered the MacBook of Linux devices.
-
The Latest CachyOS Features Supercharged Kernel
The latest release of CachyOS brings with it an enhanced version of the latest Linux kernel.
-
Kernel 7.0 Is a Bit More Rusty
Linux kernel 7.0 has been released for general availability, with Rust finally getting its due.
-
France Says "Au Revoir" to Microsoft
In a move that should surprise no one, France announced plans to reduce its reliance on US technology, and Microsoft Windows is the first to get the boot.
-
CIQ Releases Compatibility Catalog for Rocky Linux
The company behind Rocky Linux is making an open catalog available to developers, hobbyists, and other contributors, so they can verify and publish compatibility with the CIQ lineup.
-
KDE Gets Some Resuscitation
KDE is bringing back two themes that vanished a few years ago, putting a bit more air under its wings.
-
Ubuntu 26.04 Beta Arrives with Some Surprises
Ubuntu 26.04 is almost here, but the beta version has been released, and it might surprise some people.
-
Ubuntu MATE Dev Leaving After 12 years
Martin Wimpress, the maintainer of Ubuntu MATE, is now searching for his successor. Are you the next in line?
-
Kali Linux Waxes Nostalgic with BackTrack Mode
For those who've used Kali Linux since its inception, the changes with the new release are sure to put a smile on your face.
-
Gnome 50 Smooths Out NVIDIA GPU Issues
Gamers rejoice, your favorite pastime just got better with Gnome 50 and NVIDIA GPUs.
