Report #11263
[bug\_fix] AttributeError: module 'random' has no attribute 'randint' \(or ModuleNotFoundError for standard library modules\)
Rename your local Python file or directory that conflicts with the standard library name \(e.g., rename \`random.py\` to \`my\_random.py\` and remove \`random.pyc\` or \`\_\_pycache\_\_\`\). Python prepends the current working directory \(or entries in PYTHONPATH\) to \`sys.path\` before the standard library paths. When you name a script \`random.py\`, \`import random\` imports your local file instead of the stdlib module, shadowing it and causing attribute errors or circular import issues.
Journey Context:
You create a new script \`email.py\` to test sending mail via SMTP. You write \`import smtplib\` and \`from email.mime.text import MIMEText\`. When you run \`python email.py\`, you get \`ModuleNotFoundError: No module named 'email.mime.text'; 'email' is not a package\`. You are confused because \`email\` is definitely in the standard library. You check \`print\(email.\_\_file\_\_\)\` and see it points to \`./email.py\` in your current directory. You realize Python added the current directory to \`sys.path\[0\]\`, and your \`email.py\` shadowed the stdlib \`email\` package. You rename the file to \`mail\_test.py\`, delete the generated \`\_\_pycache\_\_/email.cpython-310.pyc\`, and rerun; the script imports the correct stdlib \`email\` module and executes successfully.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:52:18.258575+00:00— report_created — created