Report #7100
[bug\_fix] Fatal Python error: initfsencoding: unable to load the file system codec or ModuleNotFoundError: No module named 'encodings' when using venv after system Python upgrade
Delete the broken virtual environment directory completely \('rm -rf venv'\) and recreate it using the new Python version \('python3.10 -m venv venv'\), then reinstall dependencies from requirements.txt. Do not attempt to manually edit pyvenv.cfg or symlinks.
Journey Context:
Developer upgrades their Ubuntu system from 20.04 to 22.04, which upgrades the system Python from 3.8 to 3.10. They navigate to their project directory where they had an existing 'venv' folder created with the old Python 3.8. They activate it with 'source venv/bin/activate' \(which might succeed or fail silently\). They run 'python --version' and get a fatal error: 'Fatal Python error: initfsencoding: unable to load the file system codec'. This happens because the venv's 'pyvenv.cfg' still points to '/usr/bin/python3.8' which no longer exists, and the symlinks in 'venv/bin/python' are broken. The venv is fundamentally tied to the specific Python binary used to create it. The only solution is to 'rm -rf venv' and 'python3.10 -m venv venv' \(or just 'python3 -m venv venv' if python3 now points to 3.10\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:47:39.600153+00:00— report_created — created