Cardinal Review

Python errors on bots and apps.

Errors from Python bots and apps, pip installs and asyncio, as they appear in a server console. 8 errors, each with an example of the console line, the cause and the fix.

All 8 errors on this page
  1. Python module 'module' not installed
  2. Cannot import 'name' (version mismatch)
  3. Python syntax error
  4. Python exception (traceback)
  5. requirements.txt not found
  6. pip could not find a package version
  7. pip refused to install into the system Python
  8. Unclosed aiohttp session or pending task

Python module 'module' not installed

critical python

In the console

ModuleNotFoundError: No module named 'module'
ImportError: No module named module

Python could not import a module. It is not installed in this server's environment, or the import name differs from the package name (for example 'discord' comes from the 'discord.py' package, 'dotenv' from 'python-dotenv').

How to fix it

  1. Add the package to requirements.txt (or the egg's 'additional python packages' variable) and restart so it gets installed.
  2. Check the package name on pypi.org: the import name and the pip name are not always the same.
  3. If it is your own module, check the file exists and that the working directory is the server root.

Cannot import 'name' (version mismatch)

error python

In the console

ImportError: cannot import name 'name'

The module exists but no longer (or not yet) contains 'that name'. The installed version of a package differs from the one the code was written for, or two of your files import each other (circular import).

How to fix it

  1. Pin the package version the code expects in requirements.txt (for example discord.py>=2.3).
  2. If the error mentions a partially initialized module, restructure the imports to break the circular import.

Python syntax error

critical python

In the console

SyntaxError: message

Python could not parse a file: message. Mixed tabs and spaces cause IndentationError/TabError; new syntax (match, :=, f-string changes) needs a newer Python.

How to fix it

  1. Open the file and line shown just above the error and fix it.
  2. Use spaces consistently for indentation.
  3. If the code needs a newer Python, choose that version's Docker image on the Startup page.

Python exception (traceback)

warning python

In the console

Traceback (most recent call last):

The program raised an exception. The last line of the traceback names the error and the lines above show where it happened.

How to fix it

  1. Read the last line of the traceback (the error type and message).
  2. Follow the file names upward to the first one that is your code; that is where to look.
  3. If the program exits after this, wrap that part in try/except or fix the cause.

requirements.txt not found

error python

In the console

Could not open requirements file
No such file or directory: ' … requirements.txt'

The startup tried to install packages from requirements.txt but the file is missing from the server's root folder.

How to fix it

  1. Upload requirements.txt to the server root, or
  2. Clear the requirements file startup variable if the project does not use one.

pip could not find a package version

error python

In the console

No matching distribution found for package
Could not find a version that satisfies the requirement package
requires a different Python

pip has no release of the package for this Python version or platform, or the name or version in requirements.txt is wrong.

How to fix it

  1. Check the package name and version pin in requirements.txt against pypi.org.
  2. Some packages only support certain Python versions; pick a matching Docker image or relax the version pin.

pip refused to install into the system Python

error python

In the console

externally-managed-environment

Newer Debian/Ubuntu based images protect the system Python. pip must install into a virtual environment or the user site instead.

How to fix it

  1. Use the egg's own install mechanism (it normally passes --user or uses a virtual environment).
  2. If you control the startup command, install with 'pip install --user -r requirements.txt' or create a venv in the server folder.

Unclosed aiohttp session or pending task

info python

In the console

Unclosed client session
Task was destroyed but it is pending

The program exited or restarted without closing a network session or finishing a background task. Harmless on its own, but frequent messages mean resources are leaking.

How to fix it

  1. Close aiohttp sessions (async with ClientSession() as session) and cancel tasks on shutdown.
  2. Shut the bot down with its close() method instead of killing the loop.

Not sure which one you have?

Paste your log into the live demo, or install Cardinal Review Lite and it will point at the line for you. Lite is free.