Report #95682
[bug\_fix] AttributeError: module 'random' has no attribute 'randint' \(or ImportError\) due to local file shadowing
Identify and rename the local file or directory that shadows the standard library or third-party package \(e.g., rename \`random.py\` to \`my\_random.py\`, \`json.py\` to \`my\_json.py\`, or rename \`code/\` folder\), then delete any \`.pyc\` files and \`\_\_pycache\_\_\` directories related to the shadowing file to ensure the module search path finds the intended library.
Journey Context:
A developer creates a script named \`random.py\` in their project root to test \`random.randint\(\)\`. Later, in the same directory, they run another script that imports \`json\`, which internally imports the standard library \`random\` module. Python imports the local \`random.py\` instead of the standard library because the current directory is first in \`sys.path\`. The developer gets \`AttributeError: module 'random' has no attribute 'randint'\` or finds that \`random.\_\_file\_\_\` points to their local script. Debugging involves printing \`sys.path\` and checking \`module.\_\_file\_\_\` to see the shadowing. The fix works because removing the name conflict allows Python's import system to find the intended standard library module instead of the local file.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T19:11:04.893562+00:00— report_created — created