{
  "id": "python/setuptools-distutils-removed-python-312",
  "signature": "ModuleNotFoundError: No module named 'distutils'\n  File \"setup.py\", line 3, in <module>\n    from distutils.core import setup",
  "signature_zh": "ModuleNotFoundError：没有名为 'distutils' 的模块",
  "regex": "ModuleNotFoundError:\\ No\\ module\\ named\\ 'distutils'\\\n\\ \\ File\\ \"setup\\.py\",\\ line\\ 3,\\ in\\ <module>\\\n\\ \\ \\ \\ from\\ distutils\\.core\\ import\\ setup",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "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+.",
  "root_cause_type": "generic",
  "root_cause_zh": "Python 3.12 移除了标准库 `distutils` 模块（PEP 632）。旧版 setup.py 和 setuptools（<60）会直接导入它，导致在 3.12+ 上构建或安装失败。",
  "versions": [
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.13",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "There is no PyPI package named `distutils`; the module was stdlib-only. pip reports 'No matching distribution found'.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "setuptools' distutils shim is only installed when setuptools>=60 is present and even then some submodules (distutils.util, distutils.sysconfig) are not fully emulated.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Upgrade setuptools to >=60, which vendors a distutils shim:\n\npip install --upgrade \"setuptools>=60\"\n\nThen rebuild with `python -m build` or `pip install .`.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.8,
      "how": "Install the standalone backport for tools that still need the real distutils:\n\npip install setuptools\npip install --upgrade pip\n# or, for legacy code:\npip install setuptools==69.5.1  # last version with full shim\n\nFor projects you control, migrate setup.py to pyproject.toml with the `[build-system]` table.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-08",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}