Report #99639
[bug\_fix] AttributeError or ImportError from module shadowing after naming a file like a stdlib or popular package
Rename your local file or directory so it does not collide with the standard library or a third-party package \(e.g., rename socket.py, json.py, test.py, copy.py\), delete leftover .pyc / \_\_pycache\_\_, and update imports. Root cause: Python's import search order checks sys.path entries in order; the script's directory or current directory is inserted first, so a local module of the same name shadows the real one.
Journey Context:
You write a quick script called json.py to parse some JSON, then in another file 'import json' and try 'json.loads\(...\)'. You get AttributeError: module 'json' has no attribute 'loads'. The traceback even shows /path/to/your/json.py. You named your script exactly like the standard library module, and Python imported your local file instead of the stdlib. Renaming the file and removing the compiled cache fixes it.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-30T04:48:49.391595+00:00— report_created — created