{
  "id": "python/pip-requirements-file-encoding-error",
  "signature": "UnicodeDecodeError: 'charmap' codec can't decode byte 0x9a in position 1234: character maps to <undefined>",
  "signature_zh": "UnicodeDecodeError: 'charmap' 编解码器无法解码位置 1234 处的字节 0x9a：字符映射到 <undefined>",
  "regex": "UnicodeDecodeError:\\ 'charmap'\\ codec\\ can't\\ decode\\ byte\\ 0x9a\\ in\\ position\\ 1234:\\ character\\ maps\\ to\\ <undefined>",
  "domain": "python",
  "category": "encoding_error",
  "subcategory": null,
  "root_cause": "A requirements.txt file contains non-UTF-8 encoded characters (e.g., Windows-1252), and pip attempts to decode it using the system's default encoding.",
  "root_cause_type": "generic",
  "root_cause_zh": "requirements.txt 文件包含非 UTF-8 编码的字符（例如 Windows-1252），pip 尝试使用系统默认编码解码该文件。",
  "versions": [
    {
      "version": "3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Manually editing the file in Notepad and saving as ANSI",
      "why_fails": "Notepad's 'ANSI' encoding is often Windows-1252, which may still contain problematic bytes for other locales.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using `pip install -r requirements.txt --no-cache`",
      "why_fails": "The --no-cache flag does not affect file decoding; the error occurs during file reading, not caching.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Re-save requirements.txt with UTF-8 encoding using a proper editor",
      "success_rate": 0.95,
      "how": "Open file in VS Code or Sublime, click 'Save with Encoding' and choose UTF-8, then re-run `pip install -r requirements.txt`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Force pip to use UTF-8 encoding by setting PYTHONUTF8 environment variable",
      "success_rate": 0.85,
      "how": "On Windows: `set PYTHONUTF8=1` then `pip install -r requirements.txt`. On Linux/macOS: `PYTHONUTF8=1 pip install -r requirements.txt`",
      "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.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}