Install Python in an offline environment

If you have a system in an offline environment (either air-gapped or without access to systems outside of a specific network), then these instructions may suit your use case.

Requirements

  • a system access to the internet and curl installed
  • a user with sudo permissions on the offline system

Download the right file for your offline system

Determine the architecture of the offline system

Record the CPU architecture of the system which will have Python installed on it.

#! /bin/bash

ARCH=$(uname -i)

if [ $ARCH == "arm64" ]; then
   ARCH="aarch64"
fi

echo $ARCH

Download the file using the online system

Using the system that has network access, set the $ARCH variable collected from the offline system, and the version of Python, then retrieve the Python installation file.

#!/bin/bash

PYTHON_VERSION=3.13.12
ARCH=

# download master json file 
echo "Getting download information..."
curl -L -o python-versions.json https://raw.githubusercontent.com/astral-sh/uv/refs/heads/main/crates/uv-python/download-metadata.json

# get download url for Python version
PYTHON_PACKAGE="cpython-${PYTHON_VERSION}-linux-${ARCH}-gnu"
DOWNLOAD_URL=$(grep -A 20 "\"${PYTHON_PACKAGE}\":" python-versions.json | \
    grep -m 1 "\"url\":" | sed -E 's/.*"url": ?"([^"]+)".*/\1/')

# download installation tarball, quotes to get %2B correct
curl -L -o python-"${PYTHON_VERSION}".tgz "${DOWNLOAD_URL}"

Install Python in your offline environment

Copy the file python-$PYTHON_VERSION.tgz to the air-gapped system, set the Python version, and run the following commands:

PYTHON_VERSION=3.13.12
# create canonical directory extract tar ball
sudo mkdir -p /opt/python/"${PYTHON_VERSION}"

sudo tar xvf python-"${PYTHON_VERSION}".tgz \
    -C /opt/python/"${PYTHON_VERSION}" --strip-components=1

Verify Python installation

Verify that Python is installed by running the following command:

/opt/python/"${PYTHON_VERSION}"/bin/python --version

Customizing the package repository

If using an alternative source of Python packages, such as Posit Package Manager, package installation clients need to be configured. The examples below use repository URLs formatted for Package Manager.

Using uv

uv is a faster alternative to pip for installing Python packages. Users may install uv with pip install uv or by following the uv installation documentation.

Create a file located at /etc/uv/uv.toml to configure uv with your desired Python package repository:

/etc/uv/uv.toml
[[index]]
url = "https://packagemanager.example.com/pypi/latest/simple"
default = true

For more details on configuring package indexes with uv, see the uv index configuration documentation.

Using pip

pip is the default client for installing Python packages.

Create a file located at /etc/pip.conf containing to configure pip with your desired Python package repository:

/etc/pip.conf
[global]
index-url = https://packagemanager.example.com/pypi/latest/

For more details on configuring package indexes with pip, see the pip documentation.

See the Install Python documentation for other optional configuration steps.

Back to top