5. Python Programs¶
5.1. Interpreter directive (“Shebang”)¶
Executables written for interpretation by Python must use an appropriate
interpreter directive, or “shebang”, as the first line of the program.
This line should be of the form #!interpreter_location
.
See Interpreter Name for the interpreter name to use.
As noted in Interpreter Location, the form #!/usr/bin/env
interpreter_name
is deprecated.
5.2. Programs using the default Python¶
A package that installs a program that can be run by any version of
Python 3 must declare a dependency on python3
, with a versioned
dependency if necessary.
A package that installs a program that can be run by any version of
Python 2 must declare a dependency on python2
, with a versioned
dependency if necessary.
If the program needs the public Python module foo
, the package must
depend on the binary package that installs the foo
module.
See Module Package Names for the naming of packages that install
public Python modules.
5.3. Programs Shipping Private Modules¶
A program that specifies python3
as its interpreter may require its
own private Python modules.
These modules should be installed in /usr/share/module
, or
/usr/lib/module
if the modules are architecture-dependent
(e.g. extensions).
The rules explained in Modules Byte-Compilation apply to those private modules: the byte-compiled modules must not be shipped with the binary package, they should be generated in the package’s post-install script using the current default Python version, and removed in the pre-remove script. Modules should be byte-compiled using the current default Python version.
Programs that have private compiled extensions must either handle
multiple version support themselves, or declare a tight dependency on
the current Python version (e.g. Depends: python3 (>= 3.5),
python3 (<< 3.6)
.
5.4. Programs Using a Particular Python Version¶
A program which requires a specific minor version of Python must specify
the versioned interpreter pythonX.Y
.
The package that installs the programs must also specify a dependency on
pythonX.Y
and on any packages that install necessary
modules.
The notes on installation directories and byte-compilation for programs that support any version of Python also apply to programs supporting only a single Python version. Modules to be byte-compiled should use the same Python version as the package itself.