- LuzineDebug
- Python
Python errors: causes and fixes
The Python errors that block people most often: missing modules, indentation, NoneType, externally managed environments. Clear explanations and fixes for Windows, macOS and Linux.
Fix "ModuleNotFoundError: No module named" in Python
Python cannot find the imported module in the interpreter that runs your script. In most cases the package is installed in a diffe…
Beginner 5 min IndentationError: unexpected indentFix "IndentationError: unexpected indent" in Python
Python found a line indented more than the code structure allows. Align it with the block it belongs to, use spaces only (4 per le…
Beginner 3 min TypeError: 'NoneType' object is not subscriptableFix "'NoneType' object is not subscriptable" in Python
You are using [...] on a variable that is None. Most often a function has no return, or a method like list.sort() that returns Non…
Beginner 10 min error: externally-managed-environmentFix "error: externally-managed-environment" with pip
Your system (Debian 12+, Ubuntu 23.04+, Homebrew, Arch…) forbids pip from installing into the system Python, as defined by PEP 668…
Beginner 5 min UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 12: invalid continuat…Fix "UnicodeDecodeError: 'utf-8' codec can't decode byte" in Python
Python reads the file as UTF-8 while it was saved in another encoding, most often Windows-1252 (cp1252) or Latin-1: byte 0xe9 is a…
Beginner 10 min KeyError: 'name'Fix "KeyError" in Python (dict, pandas, os.environ)
You are reading d["name"] while the key "name" does not exist in the dict, the pandas DataFrame or os.environ. Print the available…
Beginner 5 min RecursionError: maximum recursion depth exceededFix "RecursionError: maximum recursion depth exceeded" in Python
A function calls itself more than about 1000 times, Python’s default limit. Most often the base case is never reached, or a proper…
Intermediate 15 min ImportError: attempted relative import with no known parent packageFix "attempted relative import with no known parent package" in Python
You are running a file directly (python app/main.py) that contains a relative import such as from .utils import x. Run that way, t…
Intermediate 10 min