{
  "id": "python/pip-freeze-unicode-decode-error",
  "signature": "UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte",
  "signature_zh": "UnicodeDecodeError：'utf-8' 编解码器无法解码位置 0 中的字节 0xff：无效的起始字节",
  "regex": "UnicodeDecodeError:\\ 'utf\\-8'\\ codec\\ can't\\ decode\\ byte\\ 0xff\\ in\\ position\\ 0:\\ invalid\\ start\\ byte",
  "domain": "python",
  "category": "encoding_error",
  "subcategory": null,
  "root_cause": "A site-packages .dist-info METADATA or RECORD file was written with a non-UTF-8 encoding (often cp1252 or UTF-16 on Windows), and pip freeze/install tries to read it as UTF-8.",
  "root_cause_type": "generic",
  "root_cause_zh": "某个 site-packages 下的 .dist-info METADATA 或 RECORD 文件以非 UTF-8 编码写入（Windows 上常为 cp1252 或 UTF-16），而 pip freeze/install 尝试以 UTF-8 读取。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Affects stdout/stderr only, not the file-reading path that raises the error.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The corrupt file belongs to another package's metadata, not pip itself.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "python - <<'PY'\nimport pathlib, sys\nfor p in pathlib.Path(sys.prefix).rglob('METADATA'):\n    try:\n        p.read_text(encoding='utf-8')\n    except UnicodeDecodeError:\n        print('BAD:', p)\nPY\n# then uninstall the owning package\npython -m pip uninstall -y badpkg",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "python -m pip install --force-reinstall --no-cache-dir badpkg",
      "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.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-08-04",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}