blog

here's what i'm working on

Packaging apps

February 23, 2022 — ~kai

Packaging apps is useful for running apps on multiple machines without worrying about versions.

Here is a short guide on packaging Python apps, in 20 steps. It first involves “freezing” it using PyInstaller, then bundling it into an AppImage using AppImageKit’s appimagetool.


  1. Enter your app’s source directory, all following operations occur from this directory. Create a Conda environment with conda create --name myapp
  2. Install the necessary dependencies for your app to work
  3. Install PyInstaller with conda install pyinstaller
  4. Set up variables APP=APPNAMEHERE; LOWERAPP=${APP,,} replacing APPNAMEHERE with your app name, like SCRIPT
  5. Backup your entry point script and name it LOWERAPP.py, like script.py
  6. Set up the app for freezing using pyinstaller script.py
  7. This creates script.spec, a build folder, and a dist folder
  8. Run pyinstaller script.spec to create the Unix executable. The script.spec file customizes the freezing process
  9. cd dist/script to find the resultant files, locate the executable, and test it works using ./script
    • It may fail if external data files were needed
    • If there were data files, it should have been specified in script.spec
    • Otherwise, you can also just copy necessary data files into the dist folder, cp -R * dist/script
  10. When it works, cd ..
  11. Helper functions can be obtained and sourced by
wget -q https://github.com/probonopd/AppImages/raw/master/functions.sh -O ./functions.sh
source ./functions.sh
  1. Create the AppDir using mkdir -p $APP/$APP.AppDir/usr/bin/, the specification of AppDir is here
  2. Enter the AppDir with cd $APP/$APP.AppDir, all following operations occur from this directory
  3. Copy the contents of step 9 into usr/bin, cp -Rv appsource/dist/script/* usr/bin/ #!. untested
  4. Make sure it is executable, chmod a+x usr/bin/$LOWERAPP
  5. Get the AppRun file, get_apprun
  6. In the AppDir, create a desktop entry file vim $LOWERAPP.desktop with the format:
[Desktop Entry]
Name=Lector
Comment=Read e-books
Type=Application
Terminal=false
Exec=lectormain
Icon=lectormain
Categories=Utility;Qt;Graphics;Viewer;
  1. Obtain 128x128 or 256x256 PNG icon, and save it as .DirIcon and $LOWERAPP.png (both are needed), in the desktop entry, the Icon= field should have $LOWERAPP but without the extension
  2. Bundle dependencies using copy_deps; copy_deps; copy_deps and then delete_blacklisted; move_lib
  3. Check the app is runnable using ./AppRun
  4. When it works, cd .., all following operations will occur from this directory
  5. Obtain the appimage tool and mark it as executable
wget "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage"
chmod a+x appimagetool-x86_64.AppImage
  1. With the AppDir in place, you can run ./appimagetool-x86_64.AppImage APPNAMEHERE.AppDir/

tags: code