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

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

## 根因

Python 3.12 移除了标准库 distutils 模块。旧的 setup.py 脚本或旧版 setuptools 直接导入 distutils 从而失败。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   pip install 'setuptools>=68'
export SETUPTOOLS_USE_DISTUTILS=stdlib
pip install .
   ```
2. **** (85% 成功率)
   ```
   pip install --upgrade setuptools
python -c "import setuptools, setuptools._distutils; print('ok')"
# if still failing, use build isolation:
pip install --use-pep517 .
   ```

## 无效尝试

- **** — There is no distutils package on PyPI; pip reports 'No matching distribution found for distutils'. (95% 失败率)
- **** — The module doesn't exist to import; the shim itself raises ModuleNotFoundError. (90% 失败率)
