{
  "id": "python/setuptools-distutils-removed",
  "signature": "ModuleNotFoundError: No module named 'distutils'\n\nDuring handling of the above exception, another exception occurred:\n\nImportError: cannot import name 'distutils' from setuptools",
  "signature_zh": "ModuleNotFoundError: 没有名为 'distutils' 的模块\n\n在处理上述异常期间，又发生另一个异常：\n\nImportError: 无法从 setuptools 导入名称 'distutils'",
  "regex": "ModuleNotFoundError:\\ No\\ module\\ named\\ 'distutils'\\\n\\\nDuring\\ handling\\ of\\ the\\ above\\ exception,\\ another\\ exception\\ occurred:\\\n\\\nImportError:\\ cannot\\ import\\ name\\ 'distutils'\\ from\\ setuptools",
  "domain": "python",
  "category": "module_error",
  "subcategory": null,
  "root_cause": "Python 3.12 removed distutils from the standard library; setuptools' shim (`setuptools._distutils`) is not active because setuptools is too old or the environment shadows it.",
  "root_cause_type": "generic",
  "root_cause_zh": "Python 3.12 从标准库中移除了 distutils；由于 setuptools 过旧或环境遮蔽，setuptools 的垫片（setuptools._distutils）未生效。",
  "versions": [
    {
      "version": "3.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "No such package exists on PyPI; distutils was bundled, not a standalone distribution.",
      "fail_rate": 0.98,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Not possible without recreating the venv; the interpreter version is fixed.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Upgrade setuptools to a version that provides the distutils shim: `pip install --upgrade 'setuptools>=68'`.",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.7,
      "how": "Set the env var `SETUPTOOLS_USE_DISTUTILS=stdlib` is wrong for 3.12; instead ensure `SETUPTOOLS_USE_DISTUTILS=local` and that setuptools is imported before distutils.",
      "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.89,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}