Report #97719
[bug\_fix] ModuleNotFoundError or shadowing caused by a script/module name colliding with the standard library
Rename the local file so it does not match a stdlib module \(e.g., rename \`code.py\` to \`mycode.py\`, \`json.py\` to \`config\_json.py\`, \`test.py\` to \`test\_app.py\`\). Delete any stale \`.pyc\` files and \`\_\_pycache\_\_\` directories. The root cause is that Python puts the script's directory first on \`sys.path\`, so a local \`json.py\` is found before the standard library \`json\`, breaking every transitive import that expects the stdlib module.
Journey Context:
You create \`json.py\` to test parsing, run it, and suddenly every other script that imports \`json\` fails or behaves weirdly. You see \`AttributeError: module 'json' has no attribute 'loads'\` even though you are not touching json. You inspect \`json.\_\_file\_\_\` and it points to your current working directory. You delete \`json.py\` but the problem persists because Python compiled \`json.pyc\` in \`\_\_pycache\_\_\`. After renaming the file and clearing \`\_\_pycache\_\_\`, imports resolve to the standard library again because \`sys.path\` no longer finds the shadowing module first.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-26T04:34:56.731750+00:00— report_created — created