Python - ArchWiki

Jump to content

# Python

From ArchWiki

Related articles

- /Virtual environment
- Django
- List of applications/Utilities#Python IDEs
- List of programming languages
- Python package guidelines
- mod_wsgi

From What is Python?:

- it is an interpreted, interactive, object-oriented programming language;
- it incorporates modules, exceptions, dynamic typing, very high level dynamic data types, and classes;
- it supports multiple programming paradigms beyond object-oriented programming, such as procedural and functional programming;
- it combines remarkable power with very clear syntax;
- it has interfaces to many system calls and libraries, as well as to various window systems, and is extensible in C or C++;
- it is also usable as an extension language for applications that need a programmable interface;
- it is portable—it runs on many Unix variants including Linux and macOS, and on Windows.

## Installation

Install the python package.

### Other versions

Previous and future versions of Python are available via the Arch User Repository (AUR). These are useful for applications or projects that require specific versions, or just for curiosity:

Note Python versions before 3.10 have reached end of life and are unmaintained.
Tip See also Status of Python versions.

- Python 3.15: python315AUR (pre-release)
- Python 3.14: python314-freethreadedAUR (free-threaded—with Global Interpreter Lock, or GIL, disabled)
- Python 3.13: python313AUR
- Python 3.13: python313-freethreadedAUR (free-threaded)
- Python 3.12: python312AUR
- Python 3.11: python311AUR
- Python 3.10: python310AUR
- Python 3.9: python39AUR (unmaintained)
- Python 3.8: python38AUR (unmaintained)
- Python 3.7: python37AUR (unmaintained)
- Python 3.6: python36AUR (unmaintained)
- Python 2.7: python2AUR (unmaintained)

Each of these packages installs a distinct binary named after the version number, e.g. python3.13 for Python 3.13, allowing multiple versions to coexist on a system. You can also use pyenv(1) or uv to easily install and switch between multiple versions of Python.

Extra modules and libraries for old versions of Python may be found in the AUR by searching for `python<version without period>`, e.g. searching for `python310` for Python 3.10 modules.

You can also download the source for any release on the https://www.python.org/downloads/ page.

### Alternative implementations

The python package installs CPython, the reference implementation of Python. However, there are also other implementations available. These implementations are usually based on older versions of Python and are not fully compatible with CPython.

Implementations available on Arch Linux include:

- PyPy — A Python implementation written in Python. It has speed and memory usage advantages compared to CPython.

  https://www.pypy.org || pypy, pypy3

- Jython — An implementation of the Python language written in Java. It can be used to embed Python scripting into Java programs or use Java libraries in Python programs.

  https://www.jython.org/ || jython

- micropython — Python for microcontrollers. It includes a small subset of the Python standard library and is optimized to run on microcontrollers and in constrained environments.

  https://micropython.org/ || micropythonAUR

- IronPython — An implementation of the Python programming language which is tightly integrated with .NET. It can use .NET libraries and allows .NET programs to use Python libraries.

  https://ironpython.net || ironpython2AUR, ironpython3AUR

More implementations exist. Some, such Cinder, are used internally at large technology companies. Others are historically notable but are no longer maintained due to improvements in the most popular implementations.

### Alternative shells

The python package includes an interactive Python shell/REPL which can be launched with the `python` command. The following shells are also available:

- bpython — A fancy interface for the Python interpreter.

  https://bpython-interpreter.org/ || bpython

- IPython — A powerful interactive Python shell.

  https://ipython.org/ || ipython

- Jupyter — A web-based computation application powered by IPython.

  https://jupyter.org/ || jupyterlab, jupyter-notebook

- ptpython — An advanced Python REPL built with prompt-toolkit.

  https://github.com/prompt-toolkit/ptpython || ptpythonAUR

## Package management

There are several ways to install Python packages on Arch Linux.

### Arch repositories

A large number of popular packages are available in the official repositories and AUR. This is the preferred way to install system-wide packages, and the only method officially supported on Arch Linux.

### Third-party packages

Developers working with Python may need to use packages or package versions not available in the Arch repositories. The recommended practice is to use a separate virtual environment to isolate each project, preventing conflicts with system packages in `/usr`. Various tools are available to install packages within a virtual environment:

- pip(1) — The official package installer for Python.

  https://pip.pypa.io/ || python-pip

- pipx — A specialized package installer that can only be used to install packages with CLI entrypoints (but not library packages).

  https://pipx.pypa.io || python-pipx

- Poetry — Python dependency management and packaging made easy. Poetry is a single tool to develop, build, publish, and track dependencies for Python projects.

  https://python-poetry.org/ || python-poetry

- Conda — Conda provides package, dependency, and environment management for any language. Conda was originally created for Python, and is popular for scientific computing, data science and machine learning. Conda is the package manager of the miniforge community distribution and the Anaconda and Miniconda distributions.

  https://docs.conda.io || python-condaAUR

- uv — An extremely fast Python package installer and resolver, written in Rust. A single tool to replace pip, pip-tools, pipx, poetry, pyenv, twine, virtualenv, and more.

  https://docs.astral.sh/uv/ || uv

pip, pipx, poetry and uv install packages from the Python Package Index and other indexes. Conda and Miniconda use the Anaconda repositories.

As an alternative to virtual environments, `pip install --user` can be used to install packages into the user scheme instead of `/usr`. This separates packages per-user rather than per-project. Virtual environments are usually the better choice.

See the Python Packaging User Guide for the official best practices for package management.

Note There are also tools integrating pip with pacman by automatically generating PKGBUILDs for specified PyPI packages: see Creating packages#PKGBUILD generators.
Tip pipenv provides a single CLI for Pipfile, pip and virtualenv. It is available as python-pipenv.

### Historical notes

Historically, easy_install (part of python-setuptools) was used to install packages distributed as Eggs. easy_install and Eggs have been replaced with pip and Wheels. See pip vs easy_install and Package Formats for more information.

Previous versions of pip could install third-party packages system-wide, but this caused a number of problems outlined in PEP668. The system-wide environment is now marked as an externally managed environment, and pip no longer allows system-wide installation.

## Widget bindings

The following widget toolkit bindings are available:

- Tkinter — The standard Python interface to the Tk GUI toolkit.

  https://docs.python.org/3/library/tkinter.html || python

- Qt for Python (PySide2) — The official Python bindings for Qt5.

  https://www.qt.io/qt-for-python || pyside2AUR, pyside2-toolsAUR

- Qt for Python (PySide6) — The official Python bindings for Qt6.

  https://www.qt.io/qt-for-python || pyside6, pyside6-tools

- pyQt — A set of Python bindings for Qt.

  https://riverbankcomputing.com/software/pyqt/intro || python-pyqt5, python-pyqt6

- PyGObject — Python bindings for GObject based libraries such as GTK, GStreamer, WebKitGTK, GLib, and GIO.

  https://pygobject.readthedocs.io/ || python-gobject

- wxPython — A cross-platform GUI toolkit for Python which wraps wxWidgets.

  https://wxpython.org/ || python-wxpython

To use these with Python, you may also need to install the associated widget toolkit packages (e.g. tk must also be installed to use Tkinter).

## Tips and tricks

### Virtual environment

Python provides tools to create isolated virtual environments into which packages may be installed without conflicting with other virtual environments or the system packages. Virtual environments can also run applications with different versions of Python on the same system.

See Python/Virtual environment for details.

### Tab completion in Python shell

Tab completion is available in the interactive shell by default. Note that the readline completer will only complete names in the global namespace. You can use python-jedi for a richer tab completion experience [1].

### List packages built for a specific Python version

Sometimes it is useful to know which installed packages were built for a specific version of Python. For example,

    $ pacman -Qoq /usr/lib/python3.12

will list all those built for Python version 3.12. This is especially useful when the official Python version is updated and one wants to get a list of packages from the AUR that need rebuilding because they were built for a possibly no longer installed Python version, see #Module not found after Python version update.

## Troubleshooting

### Module not found after Python version update

A Python-based application might output `No module named module_name` for an installed dependency named `module_name` after having upgraded the python package to a new minor version (e.g. from version 3.10 to 3.11).

The above scenario happens when a dependency is not available for that Python version or not installed at all. Python packages are installed in a versioned site-packages directory (`/usr/lib/pythonX.Y/site-packages` if system-wide, or `~/.local/lib/pythonX.Y/site-packages/` if per-user, where `X.Y` is a version like "3.11"). So whenever there is a new minor version upgrade, the Python-based package built with previous Python version must be rebuilt against the new one in order to be properly used.

Please notice it is the user's responsibility to rebuild non-official packages, including Python-based packages installed from AUR. See AUR#Updating packages and FAQ#What if I run a full system upgrade and there will be an update for a shared library, but not for the applications that depend on it?

## See also

### Official

- Official Python documentation (Can be installed with the python-docs package for offline access.)
- Official Python tutorial

### Third-Party

- Automate the Boring Stuff with Python - Creative Commons book
- Awesome Python - A curated list of Python resources
- A Byte of Python - Creative Commons book
- Cracking Codes With Python - Free online book
- Crash into Python - Free tutorial
- Python Debugging With Pdb - Guide to using `pdb`, the Python debugger
- Dive Into Python - Creative Commons book
- Fluent Python - Commercial book
- Introducing Python - Commercial book
- Invent Your Own Computer Games with Python - Free online book
- Learn Python - Free interactive tutorial
- Learn Python the Hard Way - Commercial book
- Pythonspot Python Tutorials - Free online tutorials
- Think Python - Creative Commons book

Category:

- Programming languages

Python
Add topic