To build an AppImage from a Python application you will need to bundle every single dependency (including the Python interpreter). To achieve this we will use conda, a “package , dependency and environment management for any language”. Also we will use linuxdeploy and its plugin for conda.
You can find the whole template project here
Building the AppDir
To create an AppImage you will need to create following files:
Desktop Entry
[Desktop Entry]
Version=1.0
Type=Application
Name=python_appimage_template
Comment=Template Python Application
TryExec=pythom-appimage-template.py
Exec=pythom-appimage-template.py %F
Icon=appimage_logo
Categories=Utility;
This must be deployed into AppDir/usr/share/applications/net.developer.myappname.desktop
.
It’s recommended to use the reverse domain notation for the desktop entry name as this will be
used as application id.
Icon
The application icon must be deployed to AppDir/usr/share/icons/hicolor/scalable/application-icon.svg
if
it’s a vector image otherwise it should be deployed in the folder corresponding to its size. For more
details please check the FreeDesktop Icon Theme Specification.
Notice that the icon name specified in the desktop entry must match the file name without the file extension.
Launcher script
#!/bin/sh
# -*- coding: utf-8 -*-
APPDIR=`dirname $0`
${APPDIR}/usr/conda/bin/python ${APPDIR}/usr/bin/pythom-appimage-template.py $@
This is an small wrapper to ensure our app (in this case pythom-appimage-template.py
) is
executed used the embed Python distribution.
It must be deployed to AppDir/AppRun
.
Generating the AppImage
To generate the AppImage from the AppDir we will use linuxdeploy and its
plugin for conda. It requires two input
environment variables: CONDA_CHANNELS
and CONDA_PACKAGES
, there you will specify your
package dependencies as follows:
export CONDA_CHANNELS=mychannel;myotherchannel
export CONDA_PACKAGES=mypackage;myotherpackage
You can find for conda packages here: https://anaconda.org/anaconda/repo
Finally linuxdeploy will be called as follows:
linuxdeploy --appdir=AppDir --plugin conda --output appimage
Build pipeline
## AppImage
build:AppImage:
image: conanio/gcc48:1.14.3
stage: build
before_script:
# Upgrade Conan version
- sudo pip install --upgrade conan
# Automatic detection of your arch, compiler, etc.
- conan user
# Add AppImage specific repositories
- conan remote add appimage-conan-community https://api.bintray.com/conan/appimage-conan-community/public-conan --insert=0
# Prepare build environment
- conan install .
# download linuxdeploy conda plugin
- wget -qnc https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-conda/master/linuxdeploy-plugin-conda.sh
- chmod +x linuxdeploy-plugin-conda.sh
script:
# create AppDir
- install -D -m 755 src/launcher.sh AppDir/AppRun
- install -D -m 755 src/pythom-appimage-template.py AppDir/usr/bin/pythom-appimage-template.py
- install -D -m 644 res/appimage_logo.png AppDir/usr/share/icons/hicolor/256x256/apps/appimage_logo.png
- install -D -m 644 res/net.azubieta.python_appimage_template.desktop AppDir/usr/share/applications/net.azubieta.python_appimage_template.desktop
# build the AppImage
- . activate.sh
- export CONDA_CHANNELS=conda-forge
- export CONDA_PACKAGES=pyfiglet
- linuxdeploy --appdir=AppDir --plugin conda --output appimage
- . deactivate.sh
artifacts:
paths:
- python_appimage_template*.AppImage*
Results
Once the build is done you can find the resulting file in the jobs artifacts view.
You may also want to get a reference to the latest produced artifact in order to show it in your applications site downloads page or in the pling product page. Use the following snippet to get your own download link address:
"https://www.opencode.net/<user name>/<project name>/-/jobs/artifacts/master/raw/<artifact file path>?job=<job name>"
Be sure to replace the user name, project name, artifact file path, and job name.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.