Python 3.12.0, released on October 2, 2023, removes distutils from the standard library and stops installing setuptools by default in virtual environments created with venv. For teams upgrading applications, the immediate question is whether a dependency belongs in the build process, the running application, or both. Python’s release documentation says projects that rely on setuptools or its associated modules at runtime should declare setuptools as a dependency and install it separately. [S1][S2]

The removal of distutils follows its deprecation in Python 3.10. There is a documented compatibility option for projects that cannot yet move away from it: install setuptools, which still provides distutils. But that package is no longer part of the default environment setup. Python 3.12 also removes the bundled setuptools wheel from ensurepip, the bootstrapping module. The affected defaults include pkg_resources and easy_install as well as setuptools and distutils; an application cannot treat those names as available simply because a new environment has been created. [S2]

Python’s 3.12 notes say pip version 22.1 or later does not require setuptools to be installed in the environment. Packages based on setuptools or distutils can still be installed with pip because pip supplies setuptools in the environment it uses to build the package. That is a build-time provision, not a promise that setuptools will be present when the installed application runs. A successful package build therefore does not settle whether the application’s runtime imports are satisfied. [S2]

For an upgrade, a practical check is to create a fresh Python 3.12 virtual environment from the project’s declared dependencies, then test installation and application startup separately. Python’s venv documentation describes these environments as disposable and meant to be recreated, rather than moved or copied. An older environment with setuptools already installed would not reveal that the new default leaves it out. [S2][S3]

Do not add setuptools indiscriminately. The release notes call for a runtime dependency where a project uses it or its bundled modules; pip-managed builds are a separate case. Where the application needs it, record setuptools in the dependency declarations rather than relying on a one-off manual installation. That addresses the documented missing-package problem, not every possible Python 3.12 incompatibility. [S2]

Source documents

  1. Python 3.12.0 release pagehttps://www.python.org/downloads/release/python-3120/
  2. What’s New In Python 3.12 (v3.12.0 release tag)https://raw.githubusercontent.com/python/cpython/v3.12.0/Doc/whatsnew/3.12.rst
  3. venv documentation (v3.12.0 release tag)https://raw.githubusercontent.com/python/cpython/v3.12.0/Doc/library/venv.rst