Want to take your software engineering career to the next level? Join the mailing list for career tips & advice 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 2 years ago
Repo Created almost 6 years ago
Repo Last Updated over 2 years 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 πŸš€πŸš€πŸš€
Software engineers: It's time to get promoted. Starting NOW! Subscribe to my mailing list and I will equip you with tools, tips and actionable advice to grow in your career.
Evaluating pex for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)


.. image:: https://travis-ci.org/pantsbuild/pex.svg?branch=master :target: https://travis-ci.org/pantsbuild/pex

pex is a library for generating .pex (Python EXecutable) files which are executable Python environments in the spirit of virtualenvs <http://virtualenv.org>. pex is an expansion upon the ideas outlined in PEP 441 <http://legacy.python.org/dev/peps/pep-0441/> 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 <http://pantsbuild.org/>, Buck <http://facebook.github.io/buck/>, and {py}gradle <https://github.com/linkedin/pygradle>_ also support building .pex files directly.

Still unsure about what pex does or how it works? Watch this quick lightning talk: WTF is PEX? <http://www.youtube.com/watch?v=NmpnGhRwsu0>_.

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 webserver.py in an environment containing flask as a quick way to experiment:

.. code-block:: bash

$ pex flask -- webserver.py

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 https://pex.readthedocs.io.


pex uses tox <https://testrun.org/tox/en/latest/>_ 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: http://pantsbuild.org/howto_contribute.html

pex open issues Ask a question     (View All Issues)
  • over 3 years Support --constraints
  • over 3 years .bootstrap import path leak for pkg_resources in pex
  • over 3 years Update minimum setuptools requirement to supported version
  • almost 4 years pex can resolve incompatible wheels with the 'u'/UCS4 abi flag
  • almost 4 years import path leak for `six` with OSX default python
  • almost 4 years Setuptools>=21 Compatibility
  • almost 4 years py3.5 install issue
  • almost 4 years provide a helper library to extract files/resources from pex files
  • almost 4 years Pex fails to extract archive members with UTF-8 names on linux with non-UTF-8 default encoding.
  • almost 4 years Cannot extract built pex file sources in windows.
  • almost 4 years Unhandled `TypeError` when passing non-local platform without `-o`.
  • almost 4 years PexBuilder.add_dist_location ignores name argument
  • almost 4 years OSError: : [Errno 2] No such file or directory
  • almost 4 years importing pex.variables will may look at disk and update state
  • almost 4 years Support manylinux1 wheels
  • about 4 years Cached package source has priority over wheel, preventing build?
  • about 4 years increase test coverage in a few key areas
  • about 4 years pex does not resolve packages using -i switch when using pypi-server
  • about 4 years pex does not support the compatible release clause
  • about 4 years Passing interpreter when referencing modules on PYTHONPATH
  • about 4 years Wheel version matching differs from pip
  • over 4 years Pex file looses the executable permission of a binary file if packaged
  • over 4 years Extend wheel ABI support for pypy.
  • over 4 years Ignore package?
  • over 4 years unittest.main() doesn't work
  • over 4 years Deprecate and remove python 2.6 support.
  • over 4 years pex should handle CRC errors on zip handling more gracefully
  • over 4 years Crawler.crawl_remote returns incorrect results if index is redirected
  • over 4 years Support editable distributions/zipballs
  • over 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