Fix "ModuleNotFoundError: No module named 'discord'"
Why Python says No module named 'discord' (or 'dotenv' or 'audioop') and how to fix it on your PC, in VS Code and on your bot host with requirements.txt.
The error:
Traceback (most recent call last):
File "bot.py", line 1, in <module>
import discord
ModuleNotFoundError: No module named 'discord'Python can't find the package in the Python installation that's running your bot. Usually it's installed, just somewhere else.
1. Install it with the same Python #
Computers often have several Pythons. pip might belong to one and python to another. Use python -m pip so both are the same:
python -m pip install -U discord.py
python -c "import discord; print(discord.__version__)"On macOS/Linux use python3 in both lines; on Windows py -3.12 also works. The package name is discord.py, but you import discord.
2. Activate your virtual environment #
If you installed into a .venv, it must be active when you run the bot. Your prompt should start with (.venv):
# Windows
.venv\Scripts\activate
# macOS / Linux
source .venv/bin/activate
3. Pick the right interpreter in your editor #
In VS Code, press Ctrl+Shift+P, run Python: Select Interpreter and pick the one inside .venv. PyCharm: Settings, Project, Python Interpreter. Otherwise the Run button uses a different Python than your terminal.
4. On a bot host: requirements.txt #
On ESN Hosting, the server installs packages from requirements.txt every time it starts. If it's missing, misnamed, or inside a subfolder, nothing gets installed.
discord.py
python-dotenv
aiohttp- The file must be called exactly
requirements.txtand sit in the top folder next to your main file. - One package per line, using the pip names (see the table below).
- Restart the server and watch the install lines in the console for errors.
More detail: how to install packages for your bot.
Import name vs pip name #
| Error says | Install this |
|---|---|
No module named 'discord' | discord.py |
No module named 'dotenv' | python-dotenv |
No module named 'aiosqlite' | aiosqlite |
No module named 'yaml' | PyYAML |
No module named 'PIL' | Pillow |
No module named 'nacl' | PyNaCl (voice) |
No module named 'audioop' | Upgrade: discord.py>=2.4 (see below) |
"No module named 'audioop'" on Python 3.13 #
Python 3.13 removed the audioop module. discord.py versions before 2.4 import it, so they crash on 3.13. Upgrade discord.py (python -m pip install -U discord.py, or discord.py>=2.4 in requirements.txt), or run the bot on Python 3.12.
Named your file discord.py? #
If your own script is called discord.py, or you have a folder called discord, Python imports that instead of the library. You'll see errors like AttributeError: module 'discord' has no attribute 'Intents'. Rename it to bot.py and delete any __pycache__ folder next to it.
FAQ #
pip says it's already installed, but I still get the error.
Then it's installed into a different Python. Run python -m pip install with the exact python command that starts your bot, or activate your .venv first.
Should I pip install discord or discord.py?
discord.py. That's the real package name on PyPI.
What about discord_slash or dislash?
Those old libraries are no longer maintained. discord.py 2 has slash commands built in (app_commands).
/botfix in the ESN Systems Discord.Still stuck? Use the live chat on the panel or ask in the ESN Systems Discord. Last updated November 3, 2026.