Report #36618
[bug\_fix] AttributeError: module 'random' has no attribute 'randint' \(or similar shadowing errors\) caused by a local file named random.py
Rename the local file \(e.g., from \`random.py\` to \`my\_random.py\`\) and remove the compiled bytecode \(\`rm random.pyc \_\_pycache\_\_/random\*.pyc\`\).
Journey Context:
Developer creates a script named \`random.py\` to test random number generation. Later, they run another script or a test that imports the standard library \`random\`. They get an \`AttributeError\` or \`ImportError\` because \`import random\` imports their local file instead of the stdlib module. They check \`print\(random.\_\_file\_\_\)\` and see it points to their local script. They realize Python's \`sys.path\` puts the current directory first, causing the shadowing. Renaming the file removes the collision, allowing Python to find the standard library module.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:56:27.287014+00:00— report_created — created