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


Official Python logo

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:

   1 python3

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.

Python in Debian

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

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).

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