Python

From ArchWiki
(Redirected from Python (Español))

From What is Python?:

Python 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. Python 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. Finally, Python is portable: it runs on many Unix variants including Linux and macOS, and on Windows.

Installation

Install the python package, which provides the current release of Python 3.

Other versions

Previous and future versions of Python are available via the AUR, and may be useful for old applications that do not run on the current version, for programs intended to run on other versions, or just for curiosity:

Warning: Python versions before 3.7 have reached end of life and are unmaintained. See Status of Python versions.

Extra modules/libraries for old versions of Python may be found on the AUR by searching for python<version without period>, e.g. searching for python37 for Python 3.7 modules.

You can also use pyenv to easily switch between multiple versions of Python. 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 || ironpython-gitAUR

More implementations exist. Some, such as Stackless, Pyston and 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
https://github.com/prompt-toolkit/ptpython || ptpythonAUR

Package management

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

https://pip.pypa.io/ || python-pip
  • pipx — Closely related to pip, but creates, for the user running it, an isolated environment for each application and its associated packages, preventing conflicts with system packages. Focused on packages that can be run from the command line directly as applications. You can use pipx to install packages from the Python Package Index and other indexes.
https://pypa.github.io/pipx/ || python-pipx
  • Anaconda — An open source package management system and environment management system, originally created for Python programs. You can use Conda to install packages from the Anaconda repositories.
https://docs.conda.io/projects/conda/ || anacondaAUR
  • Miniconda — A lightweight alternative to Anaconda which installs the package manager but does not install scientific computing packages by default.
https://docs.conda.io/en/latest/miniconda.html || miniconda3AUR

When installing packages using pip, it is recommended to use a virtual environment to prevent conflicts with system packages in /usr. Alternatively, pip install --user can be used to install packages into the user scheme instead of /usr. pipx and Conda integrate environment management into their workflows.

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

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 Wheel vs Egg for more information.

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.

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 || pyside2, pyside2-tools
  • Qt for Python (PySide6) — The official Python bindings for Qt6.
https://www.qt.io/qt-for-python || pyside6, pyside6-toolsAUR
  • pyQt — A set of Python bindings for Qt.
https://riverbankcomputing.com/software/pyqt/intro || python-pyqt5
  • 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].

See also

Official

Third-Party