Report #94045
[bug\_fix] ModuleNotFoundError or AttributeError due to local file shadowing stdlib or installed package
Rename the conflicting local file or directory \(e.g., \`json.py\`, \`requests/\`\) to a non-conflicting name \(e.g., \`my\_json.py\`\).
Journey Context:
A developer creates a script named \`json.py\` in their project root to experiment with JSON handling. In the same directory, they have another script that imports \`requests\`. When running the second script, it fails with \`AttributeError: module 'json' has no attribute 'loads'\`. The developer is confused because \`requests\` is installed and \`json\` is part of the standard library. They debug by adding \`import json; print\(json.\_\_file\_\_\)\` and discover it points to their local \`/home/user/project/json.py\` instead of \`/usr/lib/python3.x/json/\_\_init\_\_.py\`. They realize Python prepends the current working directory \(or the script's directory\) to \`sys.path\` at index 0, causing local files to shadow standard library modules or installed packages. The fix is to rename the local \`json.py\` to something unique like \`json\_utils.py\`, removing the shadow and allowing Python to find the correct standard library module.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T16:26:33.807118+00:00— report_created — created