Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


A library and tool for generating .pex (Python EXecutable) files

Subscribe to updates I use pex

Statistics on pex

Number of watchers on Github 969
Number of open issues 95
Average time to close an issue 8 days
Main language Python
Average time to merge a PR 5 days
Open pull requests 33+
Closed pull requests 23+
Last commit over 1 year ago
Repo Created over 5 years ago
Repo Last Updated over 1 year ago
Size 1.44 MB
Organization / Authorpantsbuild
Latest Releasev1.3.1
Page Updated
Do you use pex? Leave a review!
View open issues (95)
View pex activity
View on github
Fresh, new opensource launches πŸš€πŸš€πŸš€
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating pex for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)


.. image:: :target:

pex is a library for generating .pex (Python EXecutable) files which are executable Python environments in the spirit of virtualenvs <>. pex is an expansion upon the ideas outlined in PEP 441 <> and makes the deployment of Python applications as simple as cp. pex files may even include multiple platform-specific Python distributions, meaning that a single pex file can be portable across Linux and OS X.

pex files can be built using the pex tool. Build systems such as Pants <>, Buck <>, and {py}gradle <>_ also support building .pex files directly.

Still unsure about what pex does or how it works? Watch this quick lightning talk: WTF is PEX? <>_.

pex is licensed under the Apache2 license.


To install pex, simply

.. code-block:: bash

$ pip install pex

You can also build pex in a git clone using tox:

.. code-block:: bash

$ tox -e py27-package
$ cp dist/pex ~/bin

This builds a pex binary in dist/pex that can be copied onto your $PATH. The advantage to this approach is that it keeps your Python environment as empty as possible and is more in-line with what pex does philosophically.

Simple Examples

Launch an interpreter with requests, flask and psutil in the environment:

.. code-block:: bash

$ pex requests flask 'psutil>2,<3'

Or instead freeze your current virtualenv via requirements.txt and execute it anywhere:

.. code-block:: bash

$ pex -r <(pip freeze) -o my_virtualenv.pex
$ deactivate
$ ./my_virtualenv.pex

Run in an environment containing flask as a quick way to experiment:

.. code-block:: bash

$ pex flask --

Launch Sphinx in an ephemeral pex environment using the Sphinx entry point sphinx:main:

.. code-block:: bash

$ pex sphinx -e sphinx:main -- --help

Build a standalone pex binary into pex.pex using the pex console_scripts entry point:

.. code-block:: bash

$ pex pex -c pex -o pex.pex

You can also build pex files that use a specific interpreter type:

.. code-block:: bash

$ pex pex -c pex --python=pypy -o pypy-pex.pex

Most pex options compose well with one another, so the above commands can be mixed and matched. For a full list of options, just type pex --help.

Integrating pex into your workflow

If you use tox (and you should!), a simple way to integrate pex into your workflow is to add a packaging test environment to your tox.ini:

.. code-block:: ini

deps = pex
commands = pex . -o dist/app.pex

Then tox -e package will produce a relocateable copy of your application that you can copy to staging or production environments.


More documentation about pex, building .pex files, and how .pex files work is available at


pex uses tox <>_ for test and development automation. To run the test suite, just invoke tox:

.. code-block:: bash

$ tox

If you don't have tox, you can generate a pex of tox:

.. code-block::

$ pex tox -c tox -o ~/bin/tox


To contribute, follow these instructions:

pex open issues Ask a question     (View All Issues)
  • almost 3 years Support --constraints
  • about 3 years .bootstrap import path leak for pkg_resources in pex
  • about 3 years Update minimum setuptools requirement to supported version
  • about 3 years pex can resolve incompatible wheels with the 'u'/UCS4 abi flag
  • about 3 years import path leak for `six` with OSX default python
  • about 3 years Setuptools>=21 Compatibility
  • about 3 years py3.5 install issue
  • about 3 years provide a helper library to extract files/resources from pex files
  • about 3 years Pex fails to extract archive members with UTF-8 names on linux with non-UTF-8 default encoding.
  • about 3 years Cannot extract built pex file sources in windows.
  • about 3 years Unhandled `TypeError` when passing non-local platform without `-o`.
  • over 3 years PexBuilder.add_dist_location ignores name argument
  • over 3 years OSError: : [Errno 2] No such file or directory
  • over 3 years importing pex.variables will may look at disk and update state
  • over 3 years Support manylinux1 wheels
  • over 3 years Cached package source has priority over wheel, preventing build?
  • over 3 years increase test coverage in a few key areas
  • over 3 years pex does not resolve packages using -i switch when using pypi-server
  • over 3 years pex does not support the compatible release clause
  • over 3 years Passing interpreter when referencing modules on PYTHONPATH
  • over 3 years Wheel version matching differs from pip
  • over 3 years Pex file looses the executable permission of a binary file if packaged
  • over 3 years Extend wheel ABI support for pypy.
  • over 3 years Ignore package?
  • over 3 years unittest.main() doesn't work
  • over 3 years Deprecate and remove python 2.6 support.
  • over 3 years pex should handle CRC errors on zip handling more gracefully
  • almost 4 years Crawler.crawl_remote returns incorrect results if index is redirected
  • almost 4 years Support editable distributions/zipballs
  • almost 4 years Preserve PEX_ env variables after calling pex
pex open pull requests (View All Pulls)
  • Specify alter_sys=True when invoking runpy.run_module
  • debug CI break.
  • Molsen/add pex root option
  • More fixes for windows
  • Make --platform/--interpreter multi-options
  • Add the ability to specify pex_root on command line
  • PEX files may depend on Homebrew's python's site-packages
  • Make it possible to use an alternate CA chain for pex
  • Make pex pypi scraping cope with HTML entities
  • Add the ability to include extensions & shared libraries in pexs.
  • crawler: Decode "&amp;" to "&" in urls
  • Fix --inherit-path
  • Deprecate old-style requirement parsing
  • More specific information in building pex documentation
  • Can I build PEX with system wide site-packages?
  • Fix old pkg_resources egg version normalization.
  • Add a test which enables PEX_VERBOSE and checks whether enabling inhe…
  • Repair the `py27-coverage-simple` tox env.
  • Normalize and edify subprocess execution.
  • Allow passing an interpreter to pex.build_pex
  • linkedin's pygradle produces pex files
  • scrub Extras from sys.path on macOS Sierra
  • URL fix to Tox Documentation in README, setuptools requirements update
  • Lazily initialize the `Variables` object to avoid implicit code execution on import.
  • Adjusted FileFinder import to work with Python 3.6
  • Add manylinux wheel support and fix a few bugs along the way
  • making sure permissions retains while building pex binary
  • Improve wheel support in pex.
  • Bump to newer travis image.
  • Adds `-m` option to saved .pex file interpreter emulation
  • Add support for manylinux resolves.
  • RFC: Prepend, not append, bundled dists to sys.path
  • Improve pex resolver caching for local dist resolves
pex questions on Stackoverflow (View All Questions)
  • Pex still good in Visual Studio 2015
  • Convert the Pex TestMethods of VS 2010 to the VS2013 with Microsoft Fakes
  • How can I get PEX to auto-generate unit tests?
  • Pex Regex Problems
  • What's the difference between PEX and DHT in the BitTorrent protocol?
  • pex packaging a simple script file
  • Pex ignores default parameter assignment
  • Where/what is the Peer Exchange (PEX) protocol specification for BitTorrent?
  • Specify which python to run a pex file
  • Package python script with pandas using PEX
  • pex interpreter fails on nix server
  • Pex and Code Contracts
  • Testing changed reference parameters using Pex
  • Python Pex: Could not satisfy all requirements
  • pants build store git metadata inside pex
  • Packing an entire Python application as a PEX file
  • binutils build fails because of pex-unix file
  • Class name collision in auto-generated Pex tests
  • Pex ignores [PexAssumeNotNull] and PexAssume.AreElementsNotNull()
  • Pex: list with non-null elements
  • Pex and unicode encoding
  • PEX 8311 direct slave write
  • Python PEX: Pack a package with its sub-packages
  • Pex: Overflow Exception when int.MinValue % -1 and Strange Path Condition
  • Pex: strange predicate in path condition for an overflow exception
  • Visual Studio 2015 RC Pex creates tests for public methods only
  • Continue Pex run in Visual Studio 2015 RC intellitest till dynamic coverage block numbers match
  • Python PEX loading
  • Packaging requirements _and_ local modules with PEX
  • PEX executable VS 2015 RC
pex list of languages used
pex latest release notes
v1.3.1 pex 1.3.1


  • scrub path when not inheriting #449
  • Fix up inherits_path tests to use new values #450
v1.3.0 pex 1.3.0


  • inherit_path allows 'prefer', 'fallback', 'false' #444
v1.2.16 pex 1.2.16


  • Change PEX re-exec variable from ENV to os.environ #441
More projects by pantsbuild View all
Other projects in Python