Report #72472
[bug\_fix] UnicodeDecodeError or locale errors during pip install in minimal Docker containers \(ASCII codec can't decode byte\)
Set the environment variable \`ENV LANG C.UTF-8\` \(or \`en\_US.UTF-8\`\) in the Dockerfile before running pip install, or set \`PYTHONUTF8=1\`.
Journey Context:
Developer builds a Docker image using \`FROM python:3.9-slim\`. The Dockerfile contains \`RUN pip install package\`. The package's \`setup.py\` reads \`README.md\` with \`open\('README.md'\)\` \(implicit ascii encoding\) to set \`long\_description\`. The build fails with \`UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 42: ordinal not in range\(128\)\`. Developer investigates and finds that \`python:3.9-slim\` images default to \`LANG=\` \(empty\) or \`POSIX\` locale. Python's \`locale.getpreferredencoding\(\)\` returns 'ANSI\_X3.4-1968' \(ASCII\). The fix is adding \`ENV LANG C.UTF-8\` before the pip install, ensuring \`open\(\)\` defaults to UTF-8. Alternatively, using \`ENV PYTHONUTF8=1\` \(PEP 540\) forces UTF-8 mode regardless of locale.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T04:14:02.612663+00:00— report_created — created