Discord.py: ImportError: No module named 'discord'

Created on 27 May 2016  路  15Comments  路  Source: Rapptz/discord.py

I have installed the module for discord properly, using python3.5 but when I compile my file, i get the above error. What do I do to fix it

invalid question

Most helpful comment

python3 -m pip install discord.py

All 15 comments

Clearly you didn't install it properly. Check if your interpreter's pip is the correct one. You might have installed it for python2.7 but running it under python3 etc.

python3 -m pip install discord.py

You both likely have a folder named discord in your project folder. Delete it. Rerun the command. This is probably a case of local overrides. To verify, move out of your project directory entirely and run the following commands:

python3
import discord

If this works with no errors, you have a local override in your project. Delete the discord folders in there.

Sorry to necro this, but I'm getting the same issue. When I run python3, then import discord, I get no errors (or text in my cmd window), but I definitely don't have any directories named discord in there. Some of my package names include the string "discord", but none are just the word so it shouldn't have an issue, right?

@ccubed very helpful, that was exactly the case with my pythonic 'project', thanks for the headsup.

having same issue

I haven麓t solved it yet.
The error message is:
import discord
ModuleNotFoundError: No module named 'discord'

I don麓t have any Discord called folder and I have 3.7 Python and I have updated pip.

Has anyone an answer?

I'm going to try and cover most of this here so that this stops being necro'd.

Firstly for those running PyCharm, beware that it is default behaviour for it to create a virtual environment in your project.

To avoid any issues simply run your pip commands in the PyCharm terminal, located on the bottom left. This should ensure your packages are being installed to the venv. If you do not want to use the venv, you can simply select a System Interpreter: File > Settings > Project > Project Interpreter > Little Cog (Top Right) > Add > System Interpreter.

Secondly, ensure you are not creating any files or folders named discord in your project. If you have any in your project, remove them, and try again.

Thirdly, ensure you are installing discord.py to the correct place.

On Linux/Mac:
python{version} -m pip install discord.py

For example:
python3.7 -m pip install discord.py

On Windows:
py -{version} -m pip install discord.py

For Example:
py -3.7 -m pip install discord.py

Lastly remember, if you install a package to Python version 3.7(and you want to use it)... You must run your bot under Python 3.7.

For example:
python3.7 my_bot_file.py

If you are unsure if your version of Python has an installed package, you can use, for example:
python3.7 -m pip show package_name or python3.7 -m pip freeze(to show all installed packages).

I hope this helps. GL!

Still doesn't work...
I have exactly this code:

import discord
from discord.ext import commands

TOKEN = 'NTM4NzYyNzM1MDM5NTQ1MzQ0.D0dvdA.()Privacy'
COPYRIGHT = ''

client = commands.Bot(command_prefix = '*')

@client.event
async def on_ready():
print('Yastoy!')

client.run(TOKEN)

And I have installed Discord.py and Python 3.7.2

Is there anything wrong?

I've followed and tried many tutorials, but any of them has worked

First of all, you're going to want to change your token now.

@EvieePy has covered most of the causes of this issue, but it's hard to determine what exactly your specific issue is, without being provided more context than that it "still doesn't work". If it's erroring on the import, the rest of your code isn't relevant, and the pertinent information would be your environment, folder and file structure, python installations, etc.

This is almost certainly not an issue with the library, so for further help, you should join either the official discord.py server or the Discord API server, as the README recommends.
For code block usage, see https://help.github.com/articles/creating-and-highlighting-code-blocks/.

Still doesn't work...
I have exactly this code:

import discord
from discord.ext import commands

TOKEN = 'NTM4NzYyNzM1MDM5NTQ1MzQ0.D0dvdA.()Privacy'
COPYRIGHT = ''

client = commands.Bot(command_prefix = '*')

@client.event
async def on_ready():
print('Yastoy!')

client.run(TOKEN)

And I have installed Discord.py and Python 3.7.2

Is there anything wrong?

I've followed and tried many tutorials, but any of them has worked

The issue is that your script is wrong, and the issue is on this line print('Yastoy!') or it's that you're running 3.7 and discord.py Async sometimes has problems with 3.7

You may have accidentally done the command: pip install discord. I've been told it's a fake package and wont work.

All this was so helpfull, Thank you so much guys :D

I'm only getting this problem in a docker environment. Any fixes for it (in docker)? ty

I heard that necromancy is fun.
So I'll add something new to this.

I have ubuntu server PC that I access remotely with putty.
I installed python to it. and I tried to install discord.py to it for a discord bot.
With the commands given above.
And it says everything installed.

Import fails.
...
Tried to find it from pythons file path, it wasn't there.
Turns out it's intalled into my user instead of the python...
So I assume, that everyone who didn't get it to work, have the same issue where it is installed, but it is installed in the wrong place.
So can somebody tell us, how the frick do we install it to the right place.

If someone got pissed by the necro, good, cuz I'm pissed too and now I'll be slightly less so.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Chicchi73930 picture Chicchi73930  路  17Comments

johndoe434 picture johndoe434  路  21Comments

haaddaa1 picture haaddaa1  路  14Comments

wolfclaws picture wolfclaws  路  17Comments

ThePiGuy24 picture ThePiGuy24  路  17Comments