Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can I not import load_dotenv?

I'm trying to code a simple discord bot in python, but it says i cant import load_dotenv, instead giving me this error:

Traceback (most recent call last):
  File "/home/pi/Rotomi/Rotomi.py", line 5, in <module>
    from dotenv import load_dotenv
ImportError: cannot import name 'load_dotenv' from 'dotenv' (/home/pi/.local/lib/python3.7/site-packages/dotenv/__init__.py)

For reference, here is my current code: https://pastebin.com/75qru00R

like image 233
Roc Star Avatar asked Jan 07 '20 05:01

Roc Star


Video Answer


2 Answers

I don't know if this still needs to be solved, but I found out that this worked for me:

from dotenv import dotenv_values
temp = dotenv_values(".env")
TOKEN = temp["DISCORD_TOKEN"] 
like image 99
Brandon Avatar answered Sep 20 '22 13:09

Brandon


Just ran into the same issue and luckily we got it solved.

The problem is the package itself. So instead of install package dotenv, what you should install is python-dotenv.

pip install python-dotenv

After that, you code shall work

like image 42
Roland Ding Avatar answered Sep 20 '22 13:09

Roland Ding