Skip to content

Bundling Python apps

probonopd edited this page Sep 15, 2019 · 24 revisions

Check out

Python knowledge is required to bundle Python apps. This page is for developers, not for users

Due to the way Python imports work and due to the way Python packages are installed on Debian and Ubuntu, it is not trivial to create working AppDirs from them.

To find out what Python files a Python app (let's say "SpiderOak") accesses, you can use

strace -eopen -f ./SpiderOak 2>&1 | grep / | grep -v ENOENT | cut -d "\"" -f 2 | sort | uniq > openedfiles

Instead, it is advised that you use, a script that sets up an isolated environment into which you can install your Python app and its dependencies that are not part of the standard library.


python2 -m pip   install --user

## python MyNewEnvironment
   python2 -m workingenv    MyNewEnvironment

cd MyNewEnvironment/
SITEPY=$(find -name | head -n 1)

cat >> $ <<EOF

cat $SITEPY >>   $
mv  $  $SITEPY

source easy_install bin/activate
cd src/

# wget ...

tar xzf * ; cd * ; python2 install

#  or
## easy_install *.egg

Then, in your AppRun file, set $PYTHONPATH to point at MyNewEnvironment/lib/python2.6

Please let me know if there is an easier way to bundle Python apps properly.

Using pip

This is an example for making an AppImage from a Python 3 PyQt application using virtualenv and pip3 and the pkg2appimage tool:

app: mu.codewith.editor

  dist: trusty
    - deb trusty trusty-updates trusty-security main universe
    - deb trusty-updates main universe
    - deb trusty-security main universe
    - python3.4-venv
    -  wget -c
    -  wget -c

  - cp ../mu.codewith.editor.png ./usr/share/icons/hicolor/256x256/
  - cp ../mu.codewith.editor.png .
  - mkdir -p usr/share/metainfo/ ; cp ../mu.appdata.xml usr/share/metainfo/
  - virtualenv --python=python3 usr
  - ./usr/bin/pip3 install mu-editor
  - cat > usr/share/applications/mu.codewith.editor.desktop <<\EOF
  - [Desktop Entry]
  - cp usr/share/applications/mu.codewith.editor.desktop .
  - usr/bin/pip3 freeze | grep "mu-editor" | cut -d "=" -f 3 >> ../VERSION

Full, working example:


Miniconda is a version of Python that can run on multiple distributions. It might be a good idea to use that, because it is supposed to be isolated from the Python in the base system (Linux distribution). appears to be using this. Let us know if you try this.

Here is a script that installs FreeCAD using Conda:

For more information, see

It looks like has grown beyond "just" Python and may evolve into an option to populate any kind of AppDir.

AppImages converted from debs

If you convert a Python application from debs, then you should bundle Python inside the AppImage and make sure it does not load Python modules from the outside by the following trick:

We can do that by modifying usr/lib/python2.7/ like this:

import sys,os
prefix = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(sys.path[0]))))
sys.path = [ prefix+s for s in sys.path if not s.startswith(prefix) ]

This works because sys.path[0] contains the directory from which Python was launched.

Avoid ctypes.util.find_library

The usual way that many wrapper libraries search for system libraries is via ctypes own function which on normal systems returns the .so filename. so in the case of VidCutter, for example:

import ctypes.util
sofile = ctypes.util.find_library('mpv')

the value of sofile should return as but within the AppDir folder structure, and thus the resulting AppImage, this wouldn't work, returning None. It seems like ctypes.util.find_library isn't AppImage friendly (only searches outside of, but not inside the AppImage).You can work around it with a simple exception clause hardcoding the lib's filename like so:

sofile = ctypes.util.find_library('mpv')
if sofile is None:
    sofile = ''

Please see for more information.

Doing everything in Python

See for an example for how to create everything using Python, including downloading and building Python itself.


You can’t perform that action at this time.