EDIT: Solved, if anyone comes across this python3.8 -m pip install python-dotenv
worked for me.
I've tried reinstalling both dotenv and python-dotenv but I'm still getting the same error. I do have the .env file in the same directory as this script.
#bot.py import os import discord from dotenv import load_dotenv load_dotenv() token=os.getenv('DISCORD_TOKEN') client = discord.Client() @client.event async def on_ready(): print(f'{client.user} has connected to Discord!') client.run(token)
The Python "ModuleNotFoundError: No module named 'dotenv'" occurs when we forget to install the python-dotenv module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install python-dotenv command.
I'm new to Python and just got exact same error. Just changed install command to what I used from a MongoDB tutorial to install PyMongo. It worked like a charm :)
python -m pip install python-dotenv
in your installation manager if it's Ubuntu or Debian try: apt install python3-dotenv
you can also try sudo pip3 install python-dotenv
to install via pip.
Whatever you do remember to include explicitly the missing 3 part.
Debian/Ubuntu have separate packages and as of the present time python
means python2
and python3
means python3
in their apt repositories. However, when it comes to your locally installed python
binary on your system which python binary it defaults to using may vary depending on what /usr/bin/python is symlinked to on your system. Some systems it's symlinked to something like python2.7
and other's it may be something like python3.5
. Similar issues exist with locally installed pip
. Hence, why using the '3' is important when installing or searching for python packages
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With