Report #11025
[bug\_fix] Importing the wrong module due to local file shadowing \(e.g., naming a script json.py\)
Rename the local file or directory so it does not shadow the intended stdlib or third-party package \(e.g., rename \`json.py\` to \`my\_json\_test.py\` and remove \`json.pyc\`/\`\_\_pycache\_\_\`\). Root cause: Python prepends the directory containing the input script \(or the current working directory when using \`-c\` or interactive mode\) to \`sys.path\[0\]\`. If a local file name matches a module being imported, it shadows the standard library or installed packages.
Journey Context:
Developer creates a new script named \`http.py\` to test an HTTP client. In that same directory, they run another script that imports \`requests\` \(which internally imports Python's \`http.client\`\). Python imports the local \`http.py\` instead of the stdlib \`http\` package, causing \`ModuleNotFoundError: No module named 'http.client'\` or an \`AttributeError\` because the local module lacks expected attributes. The developer adds \`print\(\_\_file\_\_\)\` inside the import and sees it points to their local \`./http.py\`. After renaming the file to \`http\_debug.py\` and deleting the generated \`\_\_pycache\_\_\` and \`http.pyc\` files, the import correctly resolves to the standard library.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:17:50.558299+00:00— report_created — created