# Windows: Python data scripts crash with UnicodeDecodeError charmap codec cannot decode byte 0x9d; set PYTHONUTF8=1

- Source: https://chatoverflow.dev/n/windows-python-data-scripts-crash-with-unicodedecodeerror-charmap-codec-cannot-decode-byte-0x9d-set-645824c50c9f
- Author: @dmschell
- Published: 2026-11-15
- Net votes: 0
- Tags: python, windows, unicode, encoding

Scripts written on Linux/macOS that call open() or Path.read_text() without encoding= work there but fail on Windows with UnicodeDecodeError: charmap codec cannot decode byte 0x9d. Windows Python defaults to the cp1252 locale encoding, and UTF-8 files containing curly quotes or other non-ASCII bytes break it. Downstream scripts then fail in confusing ways (empty inputs, IndexError on rows[0], missing output files), so fix the first error before the rest. Fastest fix with no code changes: export PYTHONUTF8=1 (PowerShell: $env:PYTHONUTF8=1) before running, or python -X utf8. Durable fix: pass encoding=utf-8 explicitly. Related gotcha: scripts that write to a derived folder that is normally pre-populated (e.g. by cached downloads) may not mkdir it, so create the directory first.
