Raw text below, pull request at https://github.com/python/peps/pull/1581, I’m planning to be asleep by the time CI is done, so please nobody steal my number in the meantime
~Once a rendered version is up I’ll add a link.~
Update: Rendered version is at https://www.python.org/dev/peps/pep-0632/ and text in this post has been updated
Title: Deprecate distutils module
Author: Steve Dower firstname.lastname@example.org
Discussions-To: PEP 632 - Deprecate distutils module
Type: Standards Track
The distutils module _ has for a long time recommended using the
setuptools package _ instead. Setuptools has recently integrated a
complete copy of distutils and is no longer dependent on the standard
library _. Pip has been silently replacing distutils with
setuptools when installing packages for a long time already, and the
distutils documentation has stated that it is being phased out since
2014 (or earlier). It is time to remove it from the standard library.
distutils _ is a largely undocumented and unmaintained collection
of utilities for packaging and distributing Python packages, including
compilation of native extension modules. It defines a configuration
format that describes a Python distribution and provides the tools to
convert a directory of source code into a source distribution, and
some forms of binary distribution. Because of its place in the
standard library, many updates can only be released with a major
release, and users cannot rely on particular fixes being available.
setuptools _ is a better documented and well maintained enhancement
based on distutils. While it provides very similar functionality, it
is much better able to support users on earlier Python releases, and
can respond to bug reports more quickly. A number of platform-specific
enhancements already exist in setuptools that have not been added to
distutils, and there is been a long-standing recommendation in the
distutils documentation to prefer setuptools.
Historically, setuptools has extended distutils using subclassing and
monkeypatching, but has now taken a copy of the underlying code. _
As a result, the second last major dependency on distutils is gone and
there is no need to keep it in the standard library.
The final dependency on distutils is CPython itself, which uses it to
build native extension modules in the standard library (except on
Windows). Because this is a CPython build-time dependency, it is
possible to continue to use distutils for this specific case without
it being part of the standard library.
Deprecation and removal will make it obvious that issues should be
fixed in the setuptools project, and will reduce a source of bug
reports and unnecessary test maintenance. It will also help promote
the development of alternative build backends, which can now be
supported more easily thanks to PEP 517. _
In Python 3.10 and 3.11, distutils will be formally marked as
deprecated. All known issues will be closed at this time.
import distutils will raise a deprecation warning.
During Python 3.10 and 3.11, uses of distutils within the standard
library may change to use alternative APIs.
In Python 3.12, distutils will no longer be installed by
make install or any of the first-party distribution. Third-party
redistributors should no longer include distutils in their bundles or
This PEP makes no specification on migrating the parts of the CPython
build process that currently use distutils. Depending on
contributions, this migration may occur at any time.
After Python 3.12 is started and when the CPython build process no
longer depends on distutils being in the standard library, the entire
Lib/distutils directory and
will be removed from the repository.
Other references to distutils will be cleaned up. As of Python 3.9’s
initial release, the following modules have references in code or
The following Tools in CPython also refer to distutils. Note that none
of these are installed with CPython:
- PC/layout (references will be removed)
- Tools/msi (references will be removed)
- Tools/peg_generator (will be adapted to a different build tool)
- Tools/test2to3 (example project will be removed)
As the distutils code is already included in setuptools, there is no
need to republish it in any other form. Those who require access to
the functionality should use setuptools or an alternative build
Code that imports distutils will no longer work from Python 3.12.
The suggested migration path is to use the equivalent (though not
identical) imports from setuptools (see ), or to migrate to an
alternative build backend (see PEP 517 ).
Code already exists in setuptools to transparently switch
files using distutils onto their equivalents, and so most working
build scripts are already known to work with setuptools. Such scripts
may need to update their import statements. Consult the setuptools
documentation for specific migration advice. _
Some projects use alternate sets of patches over distutils, notably,
numpy.distutils. _ Projects that we know are doing this have been
Many build scripts use custom commands or narrowly scoped patches. As
these packages are already subject to setuptools overriding distutils,
we expect minimal disruption as a result of distutils being removed.
Scripts may still need to be updated to avoid importing distutils.
setuptools version 48 includes the complete copy of distutils, and as
such is no longer dependent on the standard library’s copy. Most
implementation issues they have faced are due to the continuing
existence of distutils in the standard library, and so removal will
improve the stability of their implementation.
There is not yet a reference implementation for the removal of
distutils from the standard library, nor is there an implementation
for CPython’s native module builds without relying on the standard
library copy of distutils.
…  distutils - Building and installing Python modules
…  setuptools - PyPI
…  setuptools Issue #417 - Adopt distutils
…  PEP 517 - A build-system independent format for source trees
…  Porting from Distutils
…  Packaging (numpy.distutils)
This document is placed in the public domain or under the
CC0-1.0-Universal license, whichever is more permissive.