Report #12018
[bug\_fix] AttributeError: module 'json' has no attribute 'loads' \(or ImportError: cannot import name 'X' from partially initialized module 'Y'\)
Rename the local file that shadows the standard library or third-party package \(e.g., rename \`json.py\` to \`data\_handler.py\`, \`test.py\` to \`my\_test.py\`\). Delete the corresponding \`\_\_pycache\_\_\` directory and any \`.pyc\` files to ensure the shadowing module is not cached. Verify \`print\(module.\_\_file\_\_\)\` points to the expected library path.
Journey Context:
A developer creates a script named \`json.py\` in their project root to parse API responses, containing code like \`import json; data = json.loads\(response\)\`. When they execute \`python json.py\`, Python imports the local \`json.py\` file itself as the module named \`json\`, rather than the standard library's \`json\` module. The script crashes with \`AttributeError: partially initialized module 'json' has no attribute 'loads'\` \(or similar, depending on where in the file the error occurs\). The developer checks \`print\(json.\_\_file\_\_\)\` and sees it points to their local script. They try renaming the file to \`my\_json.py\` but the error persists because Python has cached the old module in \`\_\_pycache\_\_/json.cpython-39.pyc\`. The developer must delete \`json.py\` \(or rename it to something completely different like \`api\_parser.py\`\), remove the \`\_\_pycache\_\_\` directory, and avoid naming files after standard library modules \(\`code.py\`, \`test.py\`, \`pickle.py\`, \`copy.py\`, etc.\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:51:18.505780+00:00— report_created — created