Skip to content

Instantly share code, notes, and snippets.

@trappitsch
Last active January 14, 2025 11:51
Show Gist options
  • Save trappitsch/c72a9ac067067abef705d77871225aab to your computer and use it in GitHub Desktop.
Save trappitsch/c72a9ac067067abef705d77871225aab to your computer and use it in GitHub Desktop.
PyApp packaging for air-gapped computers

Package PyApp app with batteries included

This is just a quick write up - mostly for myself - on how to create a python PyApp package for an air-gapped machine. This means that all dependencies, etc., will be included.

  • Download the CPython version that should be used. A list of default versions are in build.rs of PyApp
  • Unpack the distribution
  • Install the dependencies that you want to install with pip. Use the pip that is in python/bin/pip
    • Make sure that pip is run as ./pip install ..., i.e., use the right local one...
  • If wanted, make sure that the deps are now in the site-packages folder
  • Package again to a tar.gz file

Below example shows how I did this for the cowsay example on the PyApp docs website. The environmental variables can easily be set with this python script and then run. We want to embed, the PYAPP_DISTRIBUTION_PATH gives the path to the packaged cpython and the PYAPP_DISTRIBUTION_PYTHON_PATH gives the relative folder inside the archive. Also put PYAPP_SKIP_INSTALL, this will avoid pulling anything from pip.

import os
import subprocess
os.environ["PYAPP_PROJECT_NAME"] = "cowsay"
os.environ["PYAPP_PROJECT_VERSION"] = "6.1"
os.environ["PYAPP_SKIP_INSTALL"] = "1"
os.environ["PYAPP_DISTRIBUTION_EMBED"] = "1"
os.environ["PYAPP_DISTRIBUTION_PATH"] = "/home/reto/Documents/code/pyapp/tmp/pyapp-latest/mycpython.tar.gz"
os.environ["PYAPP_DISTRIBUTION_PYTHON_PATH"] = "python/bin/python3"
os.environ["PYAPP_FULL_ISOLATION"] = "1"
subprocess.run(["cargo", "build", "--release"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment