Python displays ModuleNotFoundError
Install the package in the correct environment and keep requirements.txt up to date. Each dependency must be declared and installed during deployment.
The container's Python does not have access to the modules on your computer. Each dependency must be declared and installed during deployment.
Step-by-step procedure
-
Identify the imported name
The name used in import may differ from the pip package, for example PIL comes from Pillow.
-
Check requirements.txt
Add the package and a compatible version, then save the file to the expected root.
-
Install with the correct Python
On your computer, use python -m pip install -r requirements.txt to avoid calling another pip. On the hosting, this installation runs automatically when the bot starts.
-
Restart
Confirm in the console that the installation completes without errors before launching the bot.
Test the installation on your computer
python --version
python -m pip install -r requirements.txt
python -m pip check
Sample requirements.txt
discord.py>=2.4
python-dotenv>=1.0
aiohttp>=3.9
How modules are installed
You have no terminal to run pip yourself. At start, the platform reads requirements.txt at the root of the bot, or the dependencies list of pyproject.toml, and installs the packages into a .deps folder. The installation runs again when that file or the Python version changes.
A module installed on your computer but missing from requirements.txt therefore does not exist on the server. Do not upload your venv or .venv folders: they are tied to your machine and are not used. The first command block is only for testing the project on your computer.
Fix it from the console
When the bot stops on this error, the “Crash diagnosis” card in the console shows “Missing Python module X”. The “Install X” button adds the package to requirements.txt, runs the installation again and restarts the bot.
You can also edit requirements.txt in the “Files” tab, one line per package, then restart. If the file has not changed but the installation looks incomplete, use “Reinstall dependencies” in the “Startup” tab.
Check the result
On restart, the console shows the dependency installation, then the command that was run, for example $ python -u bot.py. The fix is right when the ModuleNotFoundError line is gone and the bot comes online on Discord. If another module error appears, repeat the operation: Python stops at the first missing import and reports only one at a time.
Frequently asked questions
Why do I get ModuleNotFoundError: No module named 'discord'?
The Discord library is not declared. The imported module is called discord, but the package to write in requirements.txt is called discord.py. Add that line, then restart. The same error appears when requirements.txt sits in a subfolder instead of the root.
Which package matches my import?
The name differs for several common libraries: dotenv comes from python-dotenv, yaml from PyYAML, PIL from Pillow, cv2 from opencv-python and nacl from PyNaCl. If in doubt, search for the module name on pypi.org: the package page gives the line to install.
The missing module is one of my own files, what should I do?
No module named 'cogs' or 'utils' refers to a folder of your project, not a package to install. Check in “Files” that it was uploaded and sits next to the start file. Linux is case-sensitive: Cogs and cogs are two different folders.
What does ERROR: No matching distribution found for mean?
pip cannot find the requested package: the name is misspelled, the stated version does not exist, or it is not published for the bot’s Python version. Fix the line in requirements.txt, remove an overly strict version such as ==1.0.0, or change the Python version in the “Startup” tab.