# ModuleNotFoundError: No module named 'distutils'
  File "setup.py", line 3, in <module>
    from distutils.core import setup

- **ID:** `python/setuptools-distutils-removed-python-312`
- **Domain:** python
- **Category:** module_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Python 3.12 removed the stdlib `distutils` module (PEP 632). Legacy setup.py files and old setuptools versions (<60) import it directly, so building or installing the package fails on 3.12+.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.12 | active | — | — |
| 3.13 | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Upgrade setuptools to >=60, which vendors a distutils shim:

pip install --upgrade "setuptools>=60"

Then rebuild with `python -m build` or `pip install .`.
   ```
2. **** (80% success)
   ```
   Install the standalone backport for tools that still need the real distutils:

pip install setuptools
pip install --upgrade pip
# or, for legacy code:
pip install setuptools==69.5.1  # last version with full shim

For projects you control, migrate setup.py to pyproject.toml with the `[build-system]` table.
   ```

## Dead Ends

- **** — There is no PyPI package named `distutils`; the module was stdlib-only. pip reports 'No matching distribution found'. (95% fail)
- **** — setuptools' distutils shim is only installed when setuptools>=60 is present and even then some submodules (distutils.util, distutils.sysconfig) are not fully emulated. (60% fail)
