Python package guidelines

From ArchWiki
Revision as of 07:27, 24 September 2017 by Lahwaacz (talk | contribs) (Undo revision 490724 by Anntzer (talk) - out of scope, see the first sentence)
Jump to navigation Jump to search
Arch package guidelines

32-bitCLRCrossEclipseElectronFontFree PascalGNOMEGoHaskellJavaKDEKernelLispMinGWNode.jsNonfreeOCamlPerlPHPPythonRRubyRustVCSWebWine

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

Package naming

For Python 3 libraries use python-modulename. Also use the prefix if the package provides a program that is strongly coupled to the Python ecosystem (e.g. pip or tox). For other applications, use only the program name. In either case, the package name should be entirely lowercase.

The same applies to Python 2 only that the prefix (if needed) is python2-.

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 and easily installs files under $pkgdir/usr/lib/python<python version>/site-packages/$pkgname directory.


A distutils example PKGBUILD can be found here. It follows the form:

<python version> 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.


The Python packaging scene has largely migrated from distutils to setuptools, which is actively developed and functions as a drop-in replacement import in The main difference for packagers is that setuptools is packaged separately from Python itself, and must be specified as a makedepends.

If the resulting package includes executables which import the pkg_resources module, then setuptools must be additionally specified as a depends in the split package_*() functions; alternatively, if the PKGBUILD only installs the Python package for a single version of Python, setuptools should be moved from makedepends to depends.


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

pip doesn't know how to generate .pyo files (see In order to generate them manually after pip has installed the module, run:

python -O -m compileall "${pkgdir}/path/to/module


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

PyPI download URLs

PyPI URLs of the form${_name:0:1}/${_name}/${_name}-${pkgver}.tar.gz<footnote> were silently abandoned for new package versions in the course of 2016, replaced by a scheme using an unpredictable hash that needs to be fetched from the PyPI website each time a package must be updated[1].

As downstream packagers voiced their concerns to PyPI maintainers[2], a new stable scheme was provided[3]: PKGBUILD#source source=() array should now use the following URL templates.

Note that a custom $_name variable is used instead of $pkgname since python packages are generally named python-$_name

Source package${_name::1}/${_name}/${_name}-${pkgver}.tar.gz
Bilingual wheel package (Python 2 and Python 3 compatible)${_name::1}/$_name/$_name-$pkgver-$_name-$pkgver-py2.py3-none-any.whl
Arch specific wheel package
in this example for source_x86_64=('...'). Also _py=py36 can be used to not repeat the python version:$_py/${_name::1}/$_name/$_name-$pkgver-$_py-${_py}m-manylinux1_x86_64.whl