all Python 3until 3.12Removed from the standard libraryterm
distutils
removed modules
The old tool for building and installing packages (setup.py). Removed in Python 3.12; use setuptools, pip and the sysconfig and shutil modules.
Syntax
from distutils.core import setup # до 3.12
distutils predates pip and wheels: a setup.py with from distutils.core import setup built and installed a package. Development long ago moved to the third-party setuptools, so PEP 632 deprecated distutils in 3.10 and 3.12 removed it. How to rewrite: build packages with pyproject.toml and setuptools (from setuptools import setup) and install with pip; distutils.sysconfig becomes the sysconfig module (get_paths(), get_python_version()); distutils.spawn.find_executable becomes shutil.which(); distutils.dir_util.copy_tree becomes shutil.copytree(); LooseVersion/StrictVersion become the packaging package (packaging.version.Version). If setuptools is installed, import distutils may still work: that is its own copy, not the standard library.
Examples
# Python 3.12+
import sys
print('distutils' in sys.stdlib_module_names) # → False
# Python 3.12+
import shutil, sys, sysconfig
print(sysconfig.get_python_version() == '%d.%d' % sys.version_info[:2]) # → True
print('purelib' in sysconfig.get_paths()) # → True
print(shutil.which('no-such-program-xyz')) # → None
from distutils.spawn import find_executable
print(find_executable('no-such-program-xyz')) # → None
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy