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.
pip install pexVerified import paths — ran on the pinned version, not inferred.
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.
Ensure your build environment and target runtime Python interpreters align with PEX's `requires_python` metadata. Use `--python` or `--python-shebang` arguments to explicitly control the interpreter used by the PEX.
For most use cases, leverage the powerful command-line interface. Refer to the official documentation for advanced CLI options and examples before attempting programmatic integration.
If encountering inexplicable build issues or dependency problems, try clearing the PEX cache by removing the `~/.pex` directory. Use `--no-pypi` or `--no-cache` for isolated builds, though this impacts performance.
Upgrade to PEX version 2.91.8 or newer to correctly handle lock files containing relative paths for local project dependencies. If unable to upgrade, ensure all local project dependencies in your lock file use absolute paths.
Set the `PEX_ROOT` environment variable to a writable directory before running pex, or use the `--pex-root` argument. Example: `export PEX_ROOT=/tmp/my_pex_root` or `pex --pex-root /tmp/my_pex_root ...`.
Ensure `pex` is properly installed and its version is compatible with any integrating build systems. Upgrading `pex` or the build system (e.g., Pants) is often the solution. Using `--pex-verbosity=9` can provide more diagnostic information.
Double-check the entry point specified with `-c` (for console script) or `-e` (for module entry point) to ensure it correctly references an existing script or module within your project's `setup.py` or the provided source code.
Review your project's `requirements.txt` or direct dependency declarations for conflicting version constraints. You might need to explicitly specify compatible versions for the problematic packages or allow PEX to perform full dependency resolution if it was given pre-built artifacts without proper metadata.
No dependency data recorded yet.