Package: pex
ContentsOverviewInstallationSimple ExamplesSave Dependencies From PipEphemeral EnvironmentsUsing Entry PointsSpecifying A Specific InterpreterIntegrating pex into your workflowDocumentationDevelopmentOverviewpex is a library for generating .pex (Python EXecutable) files which are
executable Python environments in the spirit ofvirtualenvs.
pex is an expansion upon the ideas outlined inPEP 441and makes the deployment of Python applications as simple ascp.  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 thepextool.  Build systems such asPants,Buck, and{py}gradlealso
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.InstallationTo install pex, simply$pipinstallpexYou can also build pex in a git clone using tox:$tox-epackage$cpdist/pex~/binThis builds a pex binary indist/pexthat 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 ExamplesLaunch an interpreter withrequests,flaskandpsutilin the environment:$pexrequestsflask'psutil>2,<3'Save Dependencies From PipOr instead freeze your current virtualenv via requirements.txt and execute it anywhere:$pex$(pipfreeze)-omy_virtualenv.pex$deactivate$./my_virtualenv.pexEphemeral EnvironmentsRun webserver.py in an environment containingflaskas a quick way to experiment:$pexflask--webserver.pyLaunch Sphinx in an ephemeral pex environment using the Sphinx entry pointsphinx:main:$pexsphinx-esphinx:main----helpUsing Entry PointsProjects specifying aconsole_scriptsentry point in their configuration
can build standalone executables for those entry points.To build a standalonepex-tools-executable.pexbinary that runs thepex-toolsconsole script found in all pex version2.1.35and newer distributions:$pex"pex>=2.1.35"--console-scriptpex-tools--output-filepex-tools-executable.pexSpecifying A Specific InterpreterYou can also build pex files that use a specific interpreter type:$pex"pex>=2.1.35"-cpex-tools--python=pypy-opex-tools-pypy-executable.pexMost pex options compose well with one another, so the above commands can be
mixed and matched, and equivalent short options are available.For a full list of options, just typepex--help.Integrating pex into your workflowIf you use tox (and you should!), a simple way to integrate pex into your
workflow is to add a packaging test environment to yourtox.ini:[testenv:package]deps=pexcommands=pex . -o dist/app.pexThentox-epackagewill produce a relocatable copy of your application
that you can copy to staging or production environments.DocumentationMore documentation about Pex, building .pex files, and how .pex files work
is available athttps://docs.pex-tool.org.DevelopmentPex usestoxfor test and development automation. To run
the test suite, just invoke tox:$toxIf you don’t have tox, you can generate a pex of tox:$ pex tox -c tox -o ~/bin/toxTox provides many useful commands and options, explained athttps://tox.wiki/en/latest/.
Below, we provide some of the most commonly used commands used when working on Pex, but the
docs are worth acquainting yourself with to better understand how Tox works and how to do more
advanced commands.To run a specific environment, identify the name of the environment you’d like to invoke by
runningtox--listenvs-all, then invoke like this:$ tox -e fmtTo run MyPy:$ tox -e checkAll of our tox test environments allow passthrough arguments, which can be helpful to run
specific tests:$ tox -e py37-integration -- -k test_reproducible_buildTo run Pex from source, rather than through what is on your PATH, invoke via Python:$ python -m pex