Python Errors
Imports, virtual environments, encoding, concurrency and dependency conflicts.
Understanding Python errors
Python errors cluster around the import system (which is really about sys.path and the active interpreter), environment management (which interpreter and which site-packages), and concurrency (the GIL, event loops, and pickling constraints in multiprocessing). A very large share of "module not found" reports are simply the wrong interpreter, which is why the first command should always identify it.
How to debug Python errors
- Identify the interpreter and its paths:
python -c "import sys; print(sys.executable); print(sys.path)". This resolves most import errors immediately. - Install into the interpreter you are running, not the one on PATH:
python -m pip install …rather than barepip. - Read tracebacks bottom-up. The last line is the exception; the frames above show the call chain, and the relevant frame is usually your code, not the library's.
- For encoding errors, name the encoding explicitly and decide on an error policy, such as
open(path, encoding='utf-8', errors='replace'), rather than relying on the locale default. - For multiprocessing pickling errors, move the target function to module level. Closures, lambdas and locally defined classes cannot be pickled.
Tools worth reaching for
python -m pippython -c 'import sys; print(sys.path)'pip checkpy-spy dumpuv / pipx for isolation
All 35 Python errors
- asyncio: Task was destroyed but it is pending! NewThe event loop shut down while a task was still running, so its coroutine never got to finish or clean up. It usually…
- Django: Forbidden (403) CSRF verification failed. Request aborted. NewDjango rejected the POST because the CSRF token or the request Origin did not match the session. Behind a reverse…
- Django: ImproperlyConfigured: setting is not configuredDjango could not find a required setting such as SECRET_KEY, DATABASES, or ALLOWED_HOSTS. Often environment variables…
- Django: OperationalError: no such table NewThe model exists in code but not in the database. Either migrations were never applied to this database, the app was…
- FastAPI: ResponseValidationError NewThe handler returned data that does not match its response_model. Unlike a request validation error this is a 500…
- pip: No matching distribution found for X NewThe index has the project but nothing that fits this environment: no wheel for your Python version, platform or…
- pip: SSL Certificate Verify Failedpip cannot verify SSL certificates when downloading packages. Corporate proxy, firewall, or outdated CA certificates.
- Poetry: pyproject.toml changed significantly since poetry.lock was generated NewPoetry stores a hash of the dependency section in the lock file. Editing pyproject.toml by hand invalidates it, and…
- Pydantic v2: ValidationError after upgrade from v1 NewPydantic v2 is stricter and renamed much of the API. Common breakages: implicit type coercion removed, .dict()/.json()…
- Python 3.12: ModuleNotFoundError: No module named 'distutils' Newdistutils was deprecated in 3.10 and removed from the standard library in Python 3.12. Any package whose setup.py or…
- Python 3.13: ModuleNotFoundError: No module named 'cgi' NewPython 3.13 deleted the nineteen dead batteries listed in PEP 594, including cgi, cgitb, imghdr, telnetlib, crypt…
- Python pandas: Memory error loading large CSVCSV file too large to fit in memory. Need to use chunking or alternative approach.
- Python: An attempt has been made to start a new process before bootstrapping NewOn Windows and macOS multiprocessing starts children with spawn, which re-imports the main module in each one. If…
- Python: AttributeError: 'NoneType' object has no attribute 'X'A function returned None and the caller tried to access an attribute on it. Common with failed lookups, regex matches…
- Python: Cannot pickle local object in multiprocessingmultiprocessing cannot serialise local function or lambda. Need to use top-level function.
- Python: Circular import detectedModule A imports module B which imports module A, creating a circular dependency.
- Python: Deadlock with threading and GILMultiple threads deadlocked waiting for GIL and other locks. Common with C extensions.
- Python: error: externally-managed-environmentNewer Linux distros (Debian 12+, Ubuntu 23.04+) block global pip installs to protect system packages (PEP 668).
- Python: Event loop is closedAttempting to use closed asyncio event loop. Need to create new loop or fix cleanup order.
- Python: GIL causing performance bottleneckGlobal Interpreter Lock preventing true multithreading. CPU-bound tasks not parallelizing.
- Python: ImportError: attempted relative import with no known parent package NewA module using from . import x was run as a script. Executing a file directly sets its name to __main__, so it has no…
- Python: JSONDecodeError: Expecting value: line 1 column 1 (char 0) NewWhat was handed to json.loads was not JSON at all, most often an empty body, an HTML error or login page, or a…
- Python: KeyError on dict accessA dictionary key was accessed directly but does not exist. Often happens when parsing JSON from APIs you do not fully…
- Python: module compiled with NumPy 1.x cannot be run in NumPy 2.x NewNumPy 2.0 changed the C ABI. Any extension module (pandas, scipy, opencv, torch) built against NumPy 1.x crashes or…
- Python: Package version conflictpip cannot install package due to conflicting dependency versions.
- Python: RecursionError: maximum recursion depth exceededA function recursed beyond Python's recursion limit. Usually caused by a missing base case, cyclical data, or using…
- Python: RuntimeError: dictionary changed size during iteration NewA dict or set was mutated while a loop was walking it. Python detects the structural change and stops rather than…
- Python: RuntimeError: no running event loop NewAn asyncio API that requires an active loop (asyncio.create_task, asyncio.get_running_loop, or awaiting from sync…
- Python: SyntaxWarning: invalid escape sequence '\d' NewA backslash inside an ordinary string starts an escape sequence, and \d is not one of them. Python 3.12 promoted this…
- Python: TypeError: Object of type datetime is not JSON serializable Newjson.dumps only understands the built in types, so a datetime, Decimal, UUID, set or dataclass stops it. The value is…
- Python: UnicodeDecodeError: 'utf-8' codec can't decode byteBytes were decoded as UTF-8 but the source uses another encoding such as CP1252, Latin-1, or UTF-16.
- Python: Unpickling error - module not foundCannot unpickle object because module or class definition changed or missing.
- SQLAlchemy: DetachedInstanceError, parent instance is not bound to a Session NewA lazily loaded attribute was touched after its session closed. The object still exists, but the relationship it needs…
- uv: No solution found when resolving dependencies Newuv resolves the whole dependency graph at once and reports the exact conflicting constraints rather than installing…
- uv: the lockfile is out of date Newuv verifies that uv.lock matches pyproject.toml before syncing. A dependency was changed without relocking, or the…
Other categories
- AI 35Rate limits, context windows, GPU memory and model-serving failures.
- Ansible 10Unreachable hosts, become passwords, undefined variables and Jinja2 failures.
- API 14Auth headers, payload limits, versioning, idempotency and webhook signatures.
- Apple 10Command line tools, dyld, Homebrew permissions, notarisation and Keychain.
- Auth 11OIDC, SAML, Auth0, Okta, Keycloak, passkeys and MFA failures.
- BigData 11Spark, Kafka, Airflow, Snowflake, Flink and Databricks failures.
- C# 12NuGet restore, null references, EF Core migrations, async deadlocks and Blazor…
- C++ 11Segfaults, linker errors, memory corruption and template deduction failures.
- Caching 10Cache stampedes, stale content, Varnish and CloudFront failures.
- CI/CD 18GitHub Actions, GitLab CI, Jenkins, CircleCI: permissions, runners and…
- Client 21CORS, mixed content, module resolution, memory limits and framework runtime…
- Cloud 25IAM permissions, quotas, service limits and credential failures.
- Dart 10Null safety, pub version solving and build toolchain problems.
- Database 41Connections, deadlocks, constraints, replication and memory limits.
- DNS 10NXDOMAIN, SERVFAIL, timeouts, propagation and delegation problems.
- Docker 27Daemon connectivity, disk space, image pulls, ports and architecture mismatches.
- Elixir 9GenServer timeouts, supervision failures and Mix compilation problems.
- Email 8Delivery failures, relay denial, authentication, SPF, DKIM and DMARC.
- Frontend 23Hydration mismatches, bundler resolution, layout shift and font loading.
- Git 20Merge conflicts, rejected pushes, detached HEAD, LFS and repository corruption.
- Go 19Nil map assignment, concurrent map access, context cancellation and deadlocks.
- GraphQL 13Validation, depth limits, N+1 queries and fragment problems.
- gRPC 10Status codes, deadlines, message limits, TLS and HTTP/2 transport failures.
- HTTP 494xx client errors, 5xx server errors, redirects, headers and protocol problems.
- ICMP 23Destination unreachable, time exceeded, fragmentation needed and redirects.
- Ingress 8404 default backend, missing TLS secrets, IngressClass and path matching.
- Java 19Class loading, dependency resolution, connection pools and JVM version…
- JavaScript 42npm resolution, async pitfalls, hydration, memory limits and runtime type…
- Kubernetes 34CrashLoopBackOff, ImagePullBackOff, OOMKilled, RBAC, scheduling and storage.
- Logging 9Log4j, Logback, Fluentd, Logstash and CloudWatch ingestion problems.
- MessageQueue 14Kafka, RabbitMQ, SQS, NATS and Celery: lag, rebalancing and poison messages.
- Mobile 17Gradle, CocoaPods, Xcode signing, Metro bundler and toolchain mismatches.
- Monitoring 12Prometheus scrapes, Grafana data sources, OpenTelemetry exporters and agent…
- Network 35Refused connections, timeouts, resets, MTU problems and port exhaustion.
- Performance 6GC pauses, thread pool starvation and event loop blocking.
- PHP 11Memory limits, execution timeouts, autoloading, Composer and PDO connections.
- Proxy 17nginx, Envoy, HAProxy, Traefik, Caddy and Cloudflare upstream failures.
- Regex 8Catastrophic backtracking, back references, escaping and engine differences.
- Ruby 11Bundler, migrations, native extensions, encoding and asset compilation.
- Rust 19Borrow checker, ownership moves, trait bounds and lifetime mismatches.
- Scala 6Dependency resolution, binary compatibility and type inference failures.
- Security 25JWT validation, CSRF, OAuth grants, SELinux, SSH host keys and CSP.
- Serverless 11Lambda timeouts, package size limits, VPC networking and cold starts.
- Shell 13Command not found, permissions, quoting, expansion and Makefile syntax.
- Storage 13S3 permissions, NFS mounts, quotas, signed URLs and volume attachment.
- Svelte 10Store subscriptions, load functions and server/client boundaries.
- System 26Disk space, systemd units, file descriptors, OOM killer and scheduled jobs.
- Terraform 18State locks, provider auth, drift, dependency cycles and plan-time unknowns.
- Testing 18Jest, pytest, JUnit, Cypress and Playwright: fixtures, snapshots and timeouts.
- TLS 24Untrusted authorities, expiry, hostname mismatch, chains and cipher negotiation.
- TypeScript 19Assignability, missing declarations, strict null checks and generic constraints.
- Virtualization 8VirtualBox, VMware, Hyper-V, WSL, KVM and hypervisor conflicts.
- Web3 7Gas estimation, nonce management and reverted transactions.
- WebAssembly 7Compile errors, memory bounds and host binding mismatches.
- WebServer 10nginx, Apache, IIS and Caddy: binding, permissions, rewrites and TLS.
- Windows 10Installer failures, missing runtimes, update errors and permission problems.