Report #14965
[bug\_fix] ModuleNotFoundError for local file named identically to stdlib module \(e.g., json.py\)
Rename the local file to avoid shadowing the standard library \(e.g., \`json\_utils.py\` instead of \`json.py\`\). When Python resolves imports, the directory containing the running script is added to \`sys.path\` as the first element, causing local files to take precedence over standard library modules of the same name.
Journey Context:
You create a quick script \`json.py\` to test JSON parsing: \`import json; print\(json.loads\('\{\}'\)\)\`. You run it, it works. Later, you create \`main.py\` in the same directory which imports \`requests\`. You run \`python main.py\` and get \`AttributeError: module 'json' has no attribute 'loads'\`. The traceback shows \`requests\` trying to call \`json.loads\`. You check \`json.\_\_file\_\_\` and it points to \`/home/user/project/json.py\`. Your local \`json.py\` is shadowing the standard library \`json\` module because the current directory is prepended to \`sys.path\` when running \`main.py\`, and Python finds your local file first.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T22:50:25.514329+00:00— report_created — created