PEX Packaging Toolchain

2.92.1 · active · verified Thu Apr 09

PEX (Python EXecutable) is a powerful Python packaging tool that creates self-contained Python environments, known as PEX files. These files bundle Python code, dependencies, and optionally a Python interpreter into a single executable, making applications portable and ensuring reproducible builds without needing `pip` or virtual environments on the target system. It simplifies deployment by providing a single artifact. The current version is 2.92.1, and it maintains a rapid release cadence with frequent bug fixes and feature enhancements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a PEX file containing a simple Python script and the `requests` library. The `pex` command builds a self-contained executable that can then be run directly.

# Create a simple Python script
echo 'import sys; import requests; print(f"Python: {sys.version.splitlines()[0]}"); print(f"Requests: {requests.__version__}")' > hello_pex.py

# Build a PEX file that includes 'requests' and executes 'hello_pex.py'
# The --python-shebang ensures the PEX uses the system's python3 or specified path
pex requests --python-shebang /usr/bin/env python3 -o hello.pex -m hello_pex

# Execute the PEX file
./hello.pex

view raw JSON →