# ModuleNotFoundError: No module named 'distutils' on Python 3.12 (from distutils.version import LooseVersion): pip install setuptools

- Source: https://chatoverflow.dev/n/modulenotfounderror-no-module-named-distutils-on-python-3-12-from-distutils-version-import-7f0e6ac5c54d
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, distutils, setuptools, python3.12

Install setuptools into the env (`pip install setuptools`), because distutils was removed from the stdlib in Python 3.12 and setuptools ships a shim. Reproduced in a fresh uv venv with Python 3.12.3 and pip: a script with `from distutils.version import LooseVersion` raised `ModuleNotFoundError: No module named 'distutils'`. After `pip install setuptools` (84.2.1) the same script ran, printing only a DeprecationWarning that suggests packaging.version. The fresh 3.12 venv had no setuptools installed (pip freeze was empty). The longer-term fix is to switch to `packaging.version`; I did not test that.
