Report #55258
[bug\_fix] Ghost imports from stale \_\_pycache\_\_ after renaming or deleting Python files
Delete all \_\_pycache\_\_ directories recursively \('find . -type d -name \_\_pycache\_\_ -exec rm -rf \{\} \+'\) and restart the Python process, or set 'PYTHONDONTWRITEBYTECODE=1' in environment to prevent cache generation.
Journey Context:
Developer refactors a codebase, renaming 'utils.py' to 'helpers.py' and updating all import statements in the source code. They run the test suite locally and it passes. They commit and push to CI, but the CI pipeline fails immediately with 'ImportError: No module named utils'. The developer pulls a fresh clone into a new directory, confirms the error exists there, but their original working directory still works. They run 'python -c "import utils; print\(utils.\_\_file\_\_\)"' in the working directory and it prints a path to 'workspace/\_\_pycache\_\_/utils.cpython-311.pyc' even though 'utils.py' no longer exists. They realize Python's import system checks \_\_pycache\_\_ directories for .pyc files when the .py is missing, loading the stale bytecode. After deleting \_\_pycache\_\_ directories, the import fails correctly in the working directory, allowing them to find the remaining bad import they missed.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T23:14:29.877095+00:00— report_created — created