Report #102921
[bug\_fix] Import picks up a stale \`.pyc\` or an old file from a leftover \`\_\_pycache\_\_\` after moving/renaming modules
Delete \`\_\_pycache\_\_\` directories and \`.pyc\` files, then rerun: \`find . -type d -name \_\_pycache\_\_ -exec rm -rf \{\} \+\` \(and/or \`python -B\` to disable bytecode writing while debugging\). The root cause is that Python caches compiled bytecode keyed by path and mtime; when a module is moved, renamed, or a symlink is swapped, an old \`.pyc\` may still be importable and shadow the new source, especially on network filesystems or when containers share layers.
Journey Context:
You rename \`old\_utils.py\` to \`utils.py\` and delete the old file. Your import \`import utils\` still executes the old code. You add a print to \`utils.py\` and it does not appear. You check \`utils.\_\_file\_\_\` and discover it points to an orphan \`\_\_pycache\_\_/old\_utils.cpython-312.pyc\` that Python can still load. After clearing caches, the import resolves to the new source and the print appears. You add \`\_\_pycache\_\_/\` to \`.gitignore\` and a clean step to CI.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-10T04:42:40.758863+00:00— report_created — created