Python errors
- AttributeError: 'NoneType' object has no attributeYou called a method or attribute on a variable that is None. Something earlier returned None instead of the object you expected.
- ERROR: Could not find a version that satisfies the requirementpip found no release of the package that is compatible with your Python version, OS/CPU, or the version you pinned, or it could not reach the index at all. "(from versions: none)" usually means a wrong name, an unsupported Python version, or no network.
- error: externally-managed-environmentYour OS (Ubuntu 23.04+, Debian 12+, Homebrew, Fedora) blocks pip from installing into the system Python. Use a virtual environment or pipx.
- error: Failed building wheel for Xpip couldn't find a prebuilt wheel for your Python version and platform, so it tried to compile the package from source and the compile failed, usually because a compiler or C headers are missing.
- error: Microsoft Visual C++ 14.0 or greater is required.pip is compiling a package from source on Windows and needs a C++ compiler. Usually there's no prebuilt wheel for your Python version. Use a supported Python version or install the Build Tools.
- FileNotFoundError: [Errno 2] No such file or directoryPython couldn't find the file at that path. Relative paths are resolved from the current working directory, not from the script's folder, which is the cause most of the time.
- ImportError: attempted relative import with no known parent packageYou ran a file that uses relative imports (`from .x import y`) as a top-level script, so Python doesn't know which package it belongs to. Run it as a module with `python -m` from the project root.
- ImportError: cannot import name 'X' from partially initialized module 'Y' (most likely due to a circular import)Two modules import each other (directly or through a chain), so one of them is used before it has finished executing. It also happens when your own file has the same name as the library you're importing.
- ImportError: libGL.so.1: cannot open shared object file: No such file or directoryOpenCV (cv2) or another GUI-capable library needs the system OpenGL library, which minimal Linux images and Docker containers don't include. Install the system package, or use the headless OpenCV wheel.
- IndentationError: unexpected indentA line is indented more than Python expects. Line it up with the block it belongs to, and don't mix tabs and spaces.
- IndexError: list index out of rangeYou accessed a list position that doesn't exist. Lists are zero-indexed, so a list of length n has valid indexes 0 to n-1 (and -1 to -n). Often the list is empty or shorter than you assumed.
- json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)The string you passed to json.loads() (or response.json()) is not JSON at all. At char 0 it is usually empty, HTML (an error page), or plain text; later positions point at invalid JSON syntax.
- KeyErrorYou looked up a dictionary key that doesn't exist. Check the actual keys, use .get() with a default, or handle the missing case.
- ModuleNotFoundError: No module namedThe Python running your code can't find the package. It's usually installed for a different Python or virtual environment.
- ModuleNotFoundError: No module named 'distutils'distutils was removed in Python 3.12. Install setuptools (which provides a replacement), or upgrade the package that still imports distutils.
- NameError: name 'x' is not definedPython looked up a name (variable, function, module or class) and found it in no enclosing scope. Typos, missing imports, using a name before it's assigned, and scope problems are the usual causes.
- pip: command not foundThe pip command isn't on your PATH. Use python3 -m pip, or install pip for your Python.
- RecursionError: maximum recursion depth exceededA function called itself (directly or indirectly) about 1000 times without stopping. Usually a missing or wrong base case, or a property/__getattr__ that calls itself.
- RuntimeError: dictionary changed size during iterationYou added or deleted keys in a dict (or set) while looping over it. Iterate over a copy of the keys, or build a new dict instead.
- SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFramepandas warns that you're assigning to something that may be a temporary copy of a DataFrame, so the change might not reach the original. Caused by chained indexing like df[mask]['col'] = x, or by modifying a filtered subset.
- ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificatePython can't verify the server's HTTPS certificate. Usually missing CA certificates (macOS python.org installs), a corporate proxy, or an outdated certifi.
- SyntaxError: invalid syntaxPython could not parse your code. The caret points at where parsing failed; the real mistake is often on that line or the line just before it (missing bracket, quote or colon).
- TabError: inconsistent use of tabs and spaces in indentationYour file mixes tab characters and spaces for indentation. Convert everything to spaces.
- torch.cuda.OutOfMemoryError: CUDA out of memoryYour model, batch or tensors don't fit in GPU memory. Reduce batch size, use mixed precision, free unused tensors, or check another process isn't using the GPU.
- TypeError: 'float' object cannot be interpreted as an integerYou passed a float where Python needs a real integer, most often to range(). In Python 3 the / operator always returns a float, even for 10 / 2.
- TypeError: 'float' object is not iterablePython tried to loop over, unpack or call sum()/list()/max() on a single float. You meant to iterate over a list (or a range) but have one number.
- TypeError: 'int' object is not subscriptableYou used square brackets on an integer, as if it were a list, string or dict. The variable holds a number where you expected a container.
- TypeError: 'module' object is not callableYou called a module as if it were a function or class. The module and the thing inside it often share a name (datetime.datetime, tqdm.tqdm, glob.glob, socket.socket), so you imported the module when you meant the object.
- TypeError: 'NoneType' object is not iterableYou looped over, unpacked or called list()/sorted() on a value that is None. Usually a function forgot to return, returned None on some path, or you assigned the result of an in-place method like list.sort().
- TypeError: 'NoneType' object is not subscriptableYou used [] on a variable that is None. Find where it became None (often a function without return, or a failed lookup) and handle that case.
- TypeError: 'str' object is not callableYou used parentheses on something that is a string. Almost always a built-in such as str, input or a method name was overwritten by a variable, or parentheses were used where indexing or a format operator was meant.
- TypeError: can only concatenate str (not "int") to strYou used + to join a string with a number (or other non-string). Python won't convert types implicitly; format the value or convert it with str().
- TypeError: missing 1 required positional argument: 'self'An instance method was called on the class itself instead of on an instance, so Python had nothing to pass as `self`. Create an instance first, or make the method a `@staticmethod`/`@classmethod`.
- TypeError: Object of type X is not JSON serializable`json.dumps` only knows dict, list, str, int, float, bool and None. Anything else (datetime, Decimal, set, numpy types, your own classes) must be converted first.
- TypeError: string indices must be integersYou indexed a str with a string (or other non-integer) key, as if it were a dict. Usually the data is still raw JSON text, or you are iterating over a dict's keys instead of its values.
- TypeError: unhashable type: 'list'You used a mutable object (list, dict or set) as a dictionary key, a set member, or in something that needs hashing, like pandas groupby or drop_duplicates. Convert it to an immutable type such as a tuple or frozenset.
- TypeError: unsupported operand type(s) for +: 'int' and 'str'You used an operator (+, -, *, /) between two types that don't support it together, usually a number and a string (input() always returns a string) or a value that is None.
- UnboundLocalError: local variable referenced before assignmentA function assigns to a name somewhere, which makes it local for the whole function, but the code reads it before any assignment has run. Usually you meant the global variable, or a branch skipped the assignment.
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byteYou're reading a file as UTF-8 but it's in another encoding (often Windows-1252, Latin-1 or UTF-16) — or it's not text at all. Open it with the right encoding.
- ValueError: could not convert string to float`float()` got a string that isn't a valid number: empty, contains commas, currency symbols, units, or stray whitespace characters. The value in quotes in the message is the exact offending string.
- ValueError: I/O operation on closed fileYou read from or wrote to a file object (or StringIO, CSV writer, HTTP response) after it was closed, usually because the code is outside the `with` block that opened it.
- ValueError: invalid literal for int() with base 10int() was given a string that isn't a plain whole number — e.g. a decimal, an empty string, whitespace-padded text with junk, or a header row. The value after the colon shows exactly what it got.
- ValueError: setting an array element with a sequence.NumPy tried to put a list (or array) into a single numeric slot. Usually your nested lists have different lengths (a ragged array), or you assigned a sequence to one element of an array.
- ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().Python needs a single True/False, but you gave it a whole pandas Series (or NumPy array) of booleans, usually by using and/or/not or an if statement on a column.
- ValueError: too many values to unpack (expected 2)You assigned a sequence to a fixed number of variables but it contained more items. Most often from looping over a dict without .items() or splitting a string into the wrong number of parts.
- ZeroDivisionError: division by zeroThe right-hand side of `/`, `//` or `%` was zero. Usually an empty list (len 0), a total that summed to 0, or a value that defaulted to 0.