Skip to content

Developers

Valentin Niess edited this page Jun 23, 2019 · 4 revisions

This is the place where you will find more instructions for developers. Note that you might also be interested in the Users instructions, especially the embeded scheme, if you have a pure Python application.

Download

Plugin

The latest version of this plugin can be downloaded from the links above or from the release area. Select the AppImage corresponding to your architecture, e.g. linuxdeploy-plugin-python-x86_64.AppImage.

Usage

The executable can be run in standalone mode by specifying a --appdir=AppDir or as a plugin for linuxdeploy. In the later case it is activated as:

linuxdeploy [some options...] --plugin python [more options...]

Note that the plugin must be located on the search path of linuxdeploy, E.g. in the same directory.

Configuration

The behaviour of the plugin can be steered through specific environment variables. For example:

PYTHON_SOURCE="MyPythonSource"                                                 \
PYTHON_CONFIG="--enable-optimizations"                                         \
PIP_REQUIREMENTS="package1 packag2=1.0.1 package3"                             \
[extra varibales for linuxdeploy...]                                           \
linuxdeploy [some options...] --plugin python [more options...] 

where MyPythonSource is a source distribution of Python. Note that an archive or an url can be provided as well as a local source. PIP_REQUIREMNENTS are passed directly to pip and must conform to its canonical syntax. For a detailed list of the available configuration variables run the plugin in standalone (i.e. not through linuxdeploy) with --help.

Depending on the source distribution, various Python wrappers are installed in AppDir/usr/bin, e.g. python3, python3.7, etc. You can select one of those as argument to linuxdeploy --custom-apprun [any python executable...] or call them from your own AppRun entry point.

Example

the commands below builds a Python3.7 AppImage from the online source distribution:

export PYTHON_SOURCE=https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz

linuxdeploy-x86_64.AppImage --appdir AppDir \
                            --plugin python \
                            -i python.png \
                            -d python.desktop \
                            --custom-apprun AppDir/usr/bin/python3.7 \
                            --output appimage

Docker build environment

The Docker image used to build the present Python AppImages is available from DockerHub. It can be used as a base image for your own build environment, or directly to run a build script, e.g. as:

docker run --cap-add SYS_ADMIN --device /dev/fuse \
           niess/linuxdeploy-plugin-python:x86_64 /path/to/build/script.sh

Integration

Below are extra technical details, E.g. in case one wants to build a more complex application based on this plugin. Note that if your application is a pure Python one, it might be more relevant to follow the embeded scheme rather than building a dedicated AppImage with your extra packages.

  • The Python installation is done to a fixed prefix: ${APPDIR}/usr/python, inside the AppDir.

  • The Python executables installed in ${APPDIR}/usr/bin are bash wrappers. Those allow to forward the source executable ($ARGV0) to Python and to ensure that the system install, inside the image, is properly found. Yet, if you want to use the native binaries those are located in ${APPDIR}/usr/python/bin.

    Note that using the native binaries has several shortcomes due to the non relocability of some Python builtin functionalities, as well as to the fact that the install residing in the AppImage has a non static mount point.

  • The Python distribution installed inside the AppImage uses a sitecustomize.py file in order to prune the default install location (/usr/local) from the search path. This allows to isolate the Python running in the image from the host system packages.

    Yet, if you need to keep the host system packages visible you can add their location to PYTHONPATH.

Clone this wiki locally