Difference between revisions of "Python package guidelines"

From ArchWiki
Jump to: navigation, search
m (pip: Update phrasing)
(Example: Remove section that was integrated into #distutils subsection)
Line 49: Line 49:
Please do not install a directory named just {{Ic|tests}}, as it easily conflicts with other Python packages (for example, {{Ic|/usr/lib/python2.7/site-packages/tests/}}).
Please do not install a directory named just {{Ic|tests}}, as it easily conflicts with other Python packages (for example, {{Ic|/usr/lib/python2.7/site-packages/tests/}}).
== Example ==
A distutils-style example PKGBUILD can be found [https://projects.archlinux.org/abs.git/tree/prototypes/PKGBUILD-python.proto here] or at {{Ic|/usr/share/pacman/PKGBUILD-python.proto}}, which is in the {{Pkg|abs}} package.

Revision as of 21:57, 23 October 2016

Package creation guidelines

CLRCrossEclipseFree PascalGNOMEGoHaskellJavaKDEKernelLispMinGWNode.jsNonfreeOCamlPerlPHPPythonRRubyVCSWebWine

This document covers standards and guidelines on writing PKGBUILDs for Python software.

Package naming

For Python 3 libraries, use python-modulename. For applications, use the program name. In either case, the package name should be entirely lowercase.

Python 2 libraries should instead be named python2-modulename.

Versioned packages

If you need to add a versioned package then use python-modulename-version, e.g. python-colorama-0.2.5. So python dependency colorama==0.2.5 will turn into python-colorama-0.2.5 Arch package.

Installation methods

Python packages are generally installed using language-specific tools, such as pip or easy_install, which are comparable to dedicated package managers in that they are designed to fetch the source files from an online repository (usually PyPi, the Python Package Index) and track the relevant files (for a detailed comparison between the two, see pip vs easy_install).

However, for managing Python packages from within PKGBUILDs, the standard-provided distutils proves to be the most convenient solution since it uses the downloaded source package's setup.py and easily installs files under $pkgdir/usr/lib/python<python version>/site-packages/$pkgname directory.


A distutils example PKGBUILD can be found here or at /usr/share/pacman/PKGBUILD-python.proto, provided by the abs package. It follows the form:

<python version> setup.py install --root="$pkgdir/" --optimize=1


  • <python version> is replaced with the proper binary, python or python2
  • --root="$pkgdir/" prevents trying to directly install in the host system instead of inside the package file, which would result in a permission error
  • --optimize=1 compiles .pyo files so they can be tracked by pacman.


If you need to use pip (provided by python-pip and python2-pip), e.g. for installing wheel packages, remember to pass the following flags:

PIP_CONFIG_FILE=/dev/null pip install --isolated --root="$pkgdir" --ignore-installed --no-deps *.whl
  • PIP_CONFIG_FILE=/dev/null ignores {/etc,~/.config}/pip.conf that may be appending arbitrary flags to pip.
  • --isolated ignores environment variables (and again {/etc,~/.config}/pip/pip.conf) that may otherwise also be appending arbitrary flags to pip.
  • --ignore-installed is necessary until https://github.com/pypa/pip/issues/3063 is resolved (otherwise pip skips the install in the presence of an earlier --user install).
  • --no-deps ensures, that dependencies do not get packaged together with the main package.


In most cases, you should put any in the arch array since most Python packages are architecture independent.

Please do not install a directory named just tests, as it easily conflicts with other Python packages (for example, /usr/lib/python2.7/site-packages/tests/).