Build a Python Executable (PEX)


You need to create an executable .pex Python binary (aka a "PEX") out of Python source code.

For more on PEX files see:

If you need to create a Python library target instead, see Define a Python Library Target.


Define a python_binary target that you can build as a PEX using the binary goal:

$ ./pants binary myproject/src/python:my-python-binary


In a python_ binary target, you should specify:

  • A name for the PEX
  • A source Python file that contains a main function
  • A list of dependencies (optional). This list should include only Python library targets within the same project, not third-party dependencies. Any third-party dependencies should be specified in library targets.

Note: As an alternative to specifying a source file, you can define an entry_point function in your python_binary target. For example, specifying entry_point='main:run' would mean that the main function for the binary is the run() function contained in

Here's an example python_binary target:

  # Other parameters


See Also

Generated by publish_docs from dist/markdown/html/src/docs/common_tasks/pex.html 2017-03-20T13:01:47.027788