pythonimportmodule

no module named 'dotenv' python 3.8


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)

Solution

  • in your installation manager if it's Ubuntu or Debian try: apt install python3-dotenv

    you can also try sudo pip3 install 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