Project:Python/python-exec

is Article description::the tool used to wrap Python scripts for multiple implementations. In the process of wrapping, the original Python script is replaced by a special wrapper executable that invokes a proper version of the original script depending on which Python interpreter is used/requested.

Local implementation overrides
To avoid having to alter the system configuration, provides support for locally altering the most preferred Python interpreter using the EPYTHON environment variable. The variable should be set to a single Python implementation name, e.g.:

This will run the application with the specified implementation if it is supported. If the script in question does not support the specified implementation, will fall back to trying the configuration files.

Running scripts directly (stronger override/emergency)
You can also run the wrapped script directly from an appropriate subdirectory of, e.g.:

In this case, either the script will run with specified implementation, or the command will fail because of non-existing file.

This is also useful if is broken for some reason.

Configuration files
Starting with python-exec-2.3, is configured by one or more files located in. The main system configuration is specified in, and this configuration can be overrode for specific scripts by creating files.

Each of the configuration files specifies zero or more preferred implementations, one per-line, in descending preference order (i.e. the most preferred first). Additionally, implementations can be disabled from fallback use by listing their names prefixed by a hyphen. The implementations neither listed as preferences, nor disabled, are considered fallback implementations.

When running a script with no forced implementation ( EPYTHON unset and not spawned via Python interpreter), will first try to find the script variant for preferred implementations, in order. If none of the preferred implementations are supported, falls back to trying the remaining implementations that are supported yet not disabled, in wrapper-defined order.

eselect-python
provides an easy way to configure preferred/active Python interpreters. Since python-exec-2.3 / eselect-python-20160207, alters altering. Previous versions use old configuration format that was used by wrappers, python-wrapper, and older versions of python-exec.

For new versions, the preferred method of altering configuration is to use the edit mode that opens in an editor:

In order to list all supported interpreters, in preference order:

In order to set a new preferred interpreter, you can use:

Note that this will set the specified interpreter as the most preferred one, moving existing preferences lower.

Use in ebuilds
It is recommended to assume that the details of script wrapping are a private implementation detail and avoid relying on any specifics in ebuilds. Most of the time, the implicit wrapper support in the eclasses suffice. In particular:


 * distutils-r1 sets up to install wrapped scripts into appropriate directories and creates the wrapper symlinks afterward.
 * python_doexe and remaining install helpers install scripts into appropriate directories and create the wrapper symlinks.