Publishing your PyQt app as a Flatpak
Creating a Flatpak
We can also take care of distributing our PyQt application. Although the
Python Package Index (PyPI) is probably the standard way to distribute a
Python package, Flatpak should be more user friendly
for Linux users than using command line tools such as
Flatpaks are built locally using
flatpak-builder. The tool checks out the
source code and any of its custom dependencies, then builds it against a
runtime (a collection of libraries shared between flatpaks). Since we already
took care of the source code, all we need is to write a single file, the
flatpak manifest, which describes everything needed to build the package.
Create a new flatpak manifest file
This file reads that we use the
markdown module and the build info
is provided by the
python3-markdown.json manifest file. We are going
to create this manifest automatically using
and save it into the
#From within the simplemdviewer/ directory
wget https://raw.githubusercontent.com/flatpak/flatpak-builder-tools/master/pip/flatpak-pip-generator --directory-prefix ../env/bin
The generator has a single dependency to run,
installing it in the virtual environment, the tool can be run:
python3 -m pip install requirements-parser
python3 flatpak-pip-generator markdown
You should see a new
We are using the KDE Runtime, which provides Qt dependencies like QtQuick and KDE frameworks like Kirigami, so you will need the Software Development Kit (Sdk) runtime to build the app locally, and the Platform runtime to run it. More than that, the KDE Runtime is based on the general Freedesktop Runtime, which provides Python. You can read more about runtimes in the Flatpak Runtime Documentation.
org.kde.Platform, version 5.15-23.08, from Flathub:
flatpak install org.kde.Platform/x86_64/5.15-23.08 org.kde.Sdk/x86_64/5.15-23.08
We are using the PyQt Baseapp, which contains an already built and ready-to-use PyQt we can quickly add on top of the KDE Runtime, so we need to install it as well.
flatpak install com.riverbankcomputing.PyQt.BaseApp/x86-64/5.15-23.08
To attempt a first build of the flatpak, run:
flatpak-builder --verbose --force-clean flatpak-build-dir org.kde.simplemdviewer.json
You can add the flag
--install-deps-from flathub to flatpak-builder to
make it download the Sdk, Platform and Baseapp for you instead of installing
If you installed Flathub as a user repository, you will need to add the
flag to install the runtime. Otherwise you might see the error "Flatpak system
operation Deploy not allowed for user".
Test the flatpak build:
flatpak-builder --run flatpak-build-dir org.kde.simplemdviewer.json simplemdviewer
Build a distributable nightly flatpak bundle:
flatpak-builder flatpak-build-dir --repo=simplemdviewer-master --force-clean --ccache org.kde.simplemdviewer.json
flatpak build-bundle simplemdviewer-master simplemdviewer.flatpak org.kde.simplemdviewer
Now we can either distribute the
simplemdviewer.flatpak directly to the
users, or submit the application to a flatpak repository, like the most popular
App Submission Guidelines.
Other improvements you can make to your application:
- Signing the source archive with a detached signature.
- Providing copyright and licensing information for each file with REUSE.
- Learn more about building flatpak apps with our Flatpak Tutorial and the official documentation.
- Consider making it an official KDE Application, building Flatpak nightlies using KDE infrastructure.
- Follow the Flathub Quality Guidelines to refine the presentation of your application on Flathub.