# ModuleNotFoundError：没有名为 'distutils' 的模块

- **ID:** `python/setuptools-distutils-removed-python-312`
- **领域:** python
- **类别:** module_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Python 3.12 移除了标准库 `distutils` 模块（PEP 632）。旧版 setup.py 和 setuptools（<60）会直接导入它，导致在 3.12+ 上构建或安装失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.12 | active | — | — |
| 3.13 | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   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% 成功率)
   ```
   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.
   ```

## 无效尝试

- **** — There is no PyPI package named `distutils`; the module was stdlib-only. pip reports 'No matching distribution found'. (95% 失败率)
- **** — 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% 失败率)
