Report #16108
[bug\_fix] Import shadowing by local files or directories
Rename the local conflicting file or directory \(e.g., \`json.py\`, \`requests/\`\) to something that doesn't shadow standard library or installed package names, or ensure the working directory is not the first entry in \`sys.path\` by using \`python -m\` or modifying \`PYTHONPATH\`.
Journey Context:
A developer creates a new script named \`json.py\` in their project root to test JSON parsing. In the same directory, they have \`main.py\` which contains \`import json; data = json.loads\('\{\}'\)\`. When they run \`python main.py\`, they get \`AttributeError: partially initialized module 'json' has no attribute 'loads' \(most likely due to a circular import\)\` or simply that \`json\` has no attribute \`loads\`. They add \`print\(json.\_\_file\_\_\)\` and see it points to \`./json.py\` in the current directory instead of \`/usr/lib/python3.9/json/\_\_init\_\_.py\`. The current working directory is prepended to \`sys.path\`, causing their local file to shadow the standard library's \`json\` module. Similarly, a developer might have a folder named \`tqdm/\` \(empty or with code\) in their project root, and when they \`import tqdm\`, it imports the local empty folder instead of the installed \`tqdm\` library, causing \`ModuleNotFoundError\` for submodules. The fix is to rename the offending local file/folder \(e.g., \`test\_json.py\` or \`my\_tqdm\_test/\`\). The root cause is Python's module search order: \`sys.path\[0\]\` is typically the current directory \(or script directory\), checked before standard library and site-packages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:50:28.791537+00:00— report_created — created