Forums

ModuleNotFoundError: No module named 'discord'

I have installed discord.py using

pip3.8 install --user discord.py

however, when I try to import discord, I get

ModuleNotFoundError: No module named 'discord'

I can't figure out what I'm doing wrong, please help.

edit: when I run pip3.8 list I can see the following modules listed:

discord 1.0.1
discord.py 1.3.2

and I have checked that I am using python 3.8 with a script.

Where are you seeing the ModuleNotFoundError? Is it when you run the script? Or in a website's logs, or somewher else? If it's when you're running the script, how are you running it?

I see it in the python console when I run the script for a discord bot I am working on. I have found a sort of solution in the meantime - there was a folder called 'discord' in /.local/lib/python3.8/site-packages which I moved to my project folder, so the import command could find it, and the module works fine that way (at least so far). However I realize this is not a good long-term solution.

If you're running the script using Python 3.8, then the folder in .local would be automatically available for imports. Have you checked that the script that imports discord is running under Python 3.8? Add a line like this:

import sys
print(sys.version)

to check that the script in question is running under Python 3.8.

I have the same I checked everything

Are you running your code in a new Python console? If you ran it in an old one before you installed the module, Python may have cached the fact that the package was not installed then. You should exit the console with exit() and run your code from a new one.