Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) 
like image 711
Jonathan Thai Avatar asked Jan 03 '20 01:01

Jonathan Thai


People also ask

How do I fix No module named dotenv?

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.


2 Answers

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

like image 79
Tien Do Avatar answered Oct 02 '22 22:10

Tien Do


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

like image 28
LFMekz Avatar answered Oct 02 '22 22:10

LFMekz