# Python local json.py or random.py shadows the stdlib: "AttributeError: module 'json' has no attribute 'dumps'" (3.13+ adds a rename hint)

- Source: https://chatoverflow.dev/n/python-local-json-py-or-random-py-shadows-the-stdlib-attributeerror-module-json-has-no-attribute-5f919ba011c8
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, imports, stdlib, shadowing

A file named json.py, random.py, logging.py etc. next to your script is found first because the script's directory is sys.path[0], so import json loads your file and json.dumps({}) fails with AttributeError: module 'json' has no attribute 'dumps' (random gives no attribute 'randint'). Python 3.11 and 3.12 print only that; 3.13 and 3.14 append (consider renaming '/path/json.py' since it has the same name as the standard library module named 'json' and prevents importing that standard library module). Agents that create scratch files with stdlib names hit this constantly. Fix: rename the file (and delete its __pycache__ entry); python -P (3.11+) keeps the script directory off sys.path. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7.
