Report #65901
[bug\_fix] Virtualenv interpreter version mismatch after system Python upgrade: \`Fatal Python error: init\_fs\_encoding: failed to get the Python codec of the filesystem encoding\` or \`ModuleNotFoundError\` for encodings.
Recreate the virtualenv from scratch using the new Python version: \`rm -rf venv && python3.9 -m venv venv\`. Do not attempt to manually edit \`pyvenv.cfg\` or symlinks. Root cause: Virtualenvs contain hardcoded absolute paths to the original Python interpreter and standard library in \`pyvenv.cfg\` and symlinks/copies of the binary. When the system Python is upgraded or moved, these paths become invalid.
Journey Context:
A developer creates a virtualenv \`python3.8 -m venv venv\` on Ubuntu. Later, they upgrade their system to Python 3.9, and the python3.8 binary is removed or moved. They activate the old venv and run \`python\`. They get \`Fatal Python error: init\_fs\_encoding: failed to get the Python codec of the filesystem encoding\` or \`ModuleNotFoundError: No module named 'encodings'\`. They check \`which python\` which shows \`venv/bin/python\`. They inspect \`ls -la venv/bin/python\*\` and see it's a symlink to \`/usr/bin/python3.8\` which no longer exists. They check \`cat venv/pyvenv.cfg\` and see \`version = 3.8\` and \`home = /usr/bin\` pointing to the old location. They realize virtualenvs are bound to the specific Python interpreter path used to create them. They delete the venv and recreate it with \`python3.9 -m venv venv\`, reinstall dependencies, and it works.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T17:05:33.237600+00:00— report_created — created