Report #49556
[bug\_fix] AttributeError: module 'json' has no attribute 'loads' \(or ModuleNotFoundError due to shadowing\)
Rename the local file that shadows the standard library module \(e.g., 'json.py' -> 'data\_loader.py'\) and delete any residual bytecode files \('json.pyc', '\_\_pycache\_\_/json.cpython-39.pyc'\) to ensure the stale module is not cached.
Journey Context:
Developer creates a script named 'json.py' in their project root to test parsing. They run 'python json.py' successfully. Later, they run another script 'main.py' in the same directory that contains 'import json; data = json.loads\(...\)'. It fails with 'AttributeError: module 'json' has no attribute 'loads''. Inspecting 'json.\_\_file\_\_' reveals it points to the local 'json.py' instead of the standard library. The developer realizes their file shadows the stdlib. They rename it to 'test\_json.py' but the error persists because Python cached the old module in '\_\_pycache\_\_/json.cpython-39.pyc'. They delete the cache file and the import works.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:39:33.396803+00:00— report_created — created