wiki.debian.org

Translation(s): English - Français - Italiano - 한국어 - Português- 简体中文


Official Python logo

Contents

  1. Introduction
  2. Using Python
  3. Python in Debian
    1. Maintainers
    2. Supported Python Versions
  4. Debian Python Policy for Python developers
  5. Deviations from upstream
  6. Encouraged practices
  7. Installing from Source
  8. See also

Introduction

Python is a high-level, interactive, object-oriented language. Debian packages the latest stable Python 3. Debian 11 (Bullseye) was the last release to include Python 2 (see Python/FAQ#Python_2_support).

DebianWomen/PythonTutorial and the official Python documentation can help you learn Python.

Python follows a "batteries included" philosophy, meaning that the standard installation comes a comprehensive module library to do common tasks, e.g. reading and writing CSV or JSON files, datetime calculations, make HTTP requests etc. However, Python has a very rich ecosystem of hundreds of thousand additional modules for virtually every possible task. The main source for extra Python modules is the Python Package Index (?PyPi).

As mentioned above, Python is the programming language itself, but various implementation exist. The by far most common one - and the one included in Debian - is CPython, the reference implementation of the Python Software Foundation (PSF). As CPython is that common, it is very often referred simply to as "Python". Which applies to this wiki article, too. Another fairly common implementation of Python is PyPy.

The execution of software written in Python in the CPython implementation happens usually in two steps: as the first step, the source code is compiled into platform-independent Python byte code, which is written to a *.pyc . In the second step, the byte code is execute instruction by instruction by CPython interpreter known as the "Python Virtual Machine" (not to be mistake with virtual machines like Qemu/KVM or VMware). This is fully transparent for the user, both steps happen automatically when calling a program written in Python. It is import to note that CPython's byte code is platform-independent, but there is no guarantee to it is transferable between different Python releases.

Using Python

Python comes with a basic Debian installation. Executing a Python script is the same as other platforms:

   1 python3 name_of_your_script.py

As is running in an interactive prompt:

Note that running python instead of python3 will raise a "command not found" error. This is normal and from when Debian supported Python 2 and Python 3. Modern scripts should specify python3 , but if a non-Debian script needs python , you can install python-is-python3, make an alias, or make a symlink to point to Python 3.

If a Debian package relies on python 2, that is a bug that you should report against the package causing the error.

Sources available: ssh://git.debian.org//git/git/python-modules/misc/python-debian-artwork.git

Since Debian 12 (Bookworm), calling pip will trigger "error: externally-managed-environment". This is normal and due to Debian following PEP 668. The easiest workaround is to change pip to pipx . pipx creates a local user virtual environment and installs all external packages there. Depending on your needs, you may want to create a virtual environment somewhere else. If you are certain in what you're doing, pip install PACKAGE --break-system-packages will override the safeguards.

Users of other operating systems (e.g. Windows and OS X) can also benefit from this integrative effort by means of virtualization (e.g. see NeuroDebian VM page for easy way to start).

Maintainers

Within the Debian project, Python packages are maintained by individual developers and two main teams:

There are also :

The Debian project maintains all of packages in git. Here is team policy for using git for team packages.

Supported Python Versions

  • Debian Trixie contains 3.13

  • Debian Bookworm contains 3.11

  • Debian Bullseye contains 3.9, minimal support for 2.7

  • Debian Buster contains Python 2.7, 3.7

  • Debian Stretch contains Python 2.7, 3.5

  • Debian Jessie contains Python 2.7, 3.4

  • Debian Wheezy contains Python 2.7, 3.2

  • Debian Squeeze contains Python 2.5, 2.6 (the default), 3.1.

  • Debian Lenny contains Python 2.4 and 2.5 (the default).

  • Debian Testing contains some 3.x

  • Debian Unstable contains some 3.x

  • Debian experimental may also contain some (experimental!) packages 3.x

Those links list the distribution(s) that ship the given versions of python:

Debian Python Policy for Python developers

The Debian Python Policy describes conventions for packaging and distributing Python code in Debian.

Feel free to ask any questions on debian-python@lists.debian.org mailing list.

If you want to maintain a Python package, you have to know how the Debian Development works.

Deviations from upstream

Debian distributions modify upstream Python in a few ways that are important to understand. Of course, where at all possible, we try to minimize deviations from upstream, but here is an enumeration of the changes you might encounter on a Debian system (and derivatives, such as Ubuntu).

  • dist-packages instead of site-packages . Third party Python software installed from Debian packages goes into dist-packages , not site-packages . This is to reduce conflict between the system Python, and any from-source Python build you might install manually.

  • The standard profile and pstats modules are not included, due to restrictive redistribution clauses in their license that don’t meet the DFSG. cProfile and hotshot are however included.
  • In Debian 7 (Wheezy), the python-setuptools package installs the Distribute fork instead of the standard setuptools. In Debian 8 (Jessie), we reverted back to the merged setuptools project.

  • Also in Debian 7 (Wheezy), the python-virtualenv also uses distribute by default, but can enable classic setuptools with an optional switch. As above, in Debian 8 (Jessie) this just use the merged setuptools.

  • distutils setup scripts install files in /usr/local/ not sys.prefix (which is normally /usr/ ). This is because /usr/ is reserved for files installed from Debian packages. Note that /usr/local/lib/pythonX.Y/dist-packages is in sys.path so that modules not installed from Debian packages can still be accessed by the system Python. Tools like debhelper pass the --install-layout=deb option to the setup script while building a Debian package so that its installs files into /usr/ not /usr/local/ .

  • Python 2.7, 3.3, and 3.4 are multiarch aware.

Encouraged practices

Installing from Source

If you want the latest version, or a development version of Python, you will likely need to install it from source. In order to do that, first make sure you have build dependencies. As root, run: "aptitude build-dep python3"

Pick your version and download the "Gzipped source tarball" of the version of your choice from Python download page. Once you have the archive, extract it using "tar -xvf Python-<FULL VERSION NAME>.tgz". Once that is done, go to that directory with "cd Python-<FULL VERSION NAME>" and use the following command to compile Python from source: "./configure && make && make test" (as regular user). To install it globally without damaging system Python installed with APT, use the altinstall target (as root): "make altinstall".

See also


CategorySoftware | CategoryProgramming

Read the original on wiki.debian.org ↗