Python has a confusing history of tools that can be used to package and describe projects: these include distutils
in the Standard Library, distribute
, distutils2
, and setuptools
(and maybe more). It appears that distribute
and distutils2
were discontinued in favor of setuptools
, which leaves two competing standards.
To my understanding setuptools
offers far more options (e.g. declaring dependencies, tests, etc.) than distutils
, however it is not included in the Python standard library (yet?).
The Python Packaging User Guide[1] recommends now:
Use
setuptools
to define projects and create Source Distributions.
And explains:
Although you can use pure
distutils
for many projects, it does not support defining dependencies on other projects and is missing several convenience utilities for automatically populating package metadata correctly that are provided bysetuptools
. Being outside the standard library, setuptools also offers a more consistent feature set across different versions of Python, and (unlikedistutils
),setuptools
will be updated to produce the upcoming “Metadata 2.0” standard formats on all supported versions.Even for projects that do choose to use
distutils
, when pip installs such projects directly from source (rather than installing from a prebuilt wheel file), it will actually build your project usingsetuptools
instead.
However, looking into various project's setup.py files reveals that this does not seem to be an actual standard. Many packages still use distutils
and those that support setuptools
often mix setuptools
with distutils
e.g. by doing a fallback import:
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
Followed by an attempt to find a way to write a setup that can be installed by both setuptools
and distutils
. This often includes various ways of error-prone dependency checking, since distutils
does not support dependencies in the setup function.
Why are people still making the extra effort to support distutils
- is the fact that setuptools
is not in the standard library the only reason? What are the advantages of distutils
and are there any drawbacks of writing setup.py files that only support setuptools
.