[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ A ] [ B ] [ next ]

Debian Python Policy
Chapter 3 - Python Programs


3.1 Programs using the default python

Programs that can run with any version of Python should be started with #!/usr/bin/python. They must also specify a dependency on python, with a versioned dependency if necessary.

If the program needs the python module Foo, it must depend on python-foo. In the case where python-foo does not exist, but a pythonX.Y-foo package exists for the current python version, it can depend on "pythonX.Y-foo, python (>= X.Y), python (<< X.Y+1)" so that dependencies are robust upon the next major python upgrade.

You're free to use #!/usr/bin/env python, if you'd like to give the user a chance to override the Debian Python package with a local version, but it is not recommended.


3.1.1 Programs Shipping Private Modules

A program using /usr/bin/python as interpreter can come up with private python modules. These modules should be installed in /usr/lib/site-python/module, /usr/lib/pythonX.Y/site-packages/module (where pythonX.Y is the current python version).

If the private modules would pollute the name space in sys.path, the modules should be installed in /usr/lib/package (for architecture any) or /usr/share/package (for architecture all). In this case, the directory should be added to sys.path at the program startup.

Such a package must depend on "python (>= X.Y), python (<< X.Y+1)".

The rules explained in Modules Bytecompilation, Section 2.5 apply to those private modules: the bytecompiled modules must not be shipped with the package, they should be generated in the package's postinst, using the current default python version, and removed in the prerm.

TODO: Currently there is no mechanism to automatically recompile such modules when the default python version changes. The required dependency on "python (>= X.Y), python (<< X.Y+1)" ensures the package is upgraded, and hence recompiled, when the default python version changes. In the future, a mechanism may be introduced to automatically recompile such modules when the python package is upgraded, allowing such packages which support several python versions to only depend on "python (>= min.version)".


3.2 Programs Using a Particular Python Version

Programs which require a specific version of Python must start with #!/usr/bin/pythonX.Y. They must also specify a dependency on pythonX.Y and on any pythonX.Y-foo package providing necessary modules. They must not depend on any python-foo package.

Again, if you're using #!/usr/bin/env pythonX.Y, please be aware that a user might override the Debian Python package with a local version.

If the program ships private python modules, these modules should be installed in /usr/lib/pythonX.Y/site-packages/module (where pythonX.Y is the same python version the program uses) or /usr/lib/package. In the latter case, this directory should be added to sys.path at the program startup. They must not be shipped in /usr/lib/site-python/. The latter case is recommended, if the private modules would pollute the name space in sys.path.

The bytecompiled versions of the modules must not be shipped in the package, and they should be generated as explained in Modules Bytecompilation, Section 2.5, using the same pythonX.Y version as the program.


[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ A ] [ B ] [ next ]

Debian Python Policy

version 0.3.7.2

Neil Schemenauer nas@debian.org
Matthias Klose doko@debian.org
Gregor Hoffleit flight@debian.org
Josselin Mouette joss@debian.org