2

I am learning to make a discord bot in python, and I need something from the dotenv module (load_dotenv).

I am using the following code

import discord
from dotenv import load_dotenv

load_dotenv()
TOKEN = 'this token thing'

client = discord.Client()

@client.event
async def on_ready():
    print("UwU")
client.run(my token)

Right after I imported load_env I initialize it (I believe), therefor using it. When I run the .py I get the error that you get when you have a circular import.

Here's the error

  File "/Users/yeet/PycharmProjects/discord-bots/bot.py", line 2, in <module>
    from dotenv import load_dotenv
ImportError: cannot import name 'load_dotenv' from 'dotenv' (/Users/yeet/PycharmProjects/discord-bots/venv/lib/python3.8/site-packages/dotenv/__init__.py)

I read this post about it and I kind of get it but I don't see how it resonates with my situation, which is why I am posting this. I saw a solution in the provided post that said to use %reset in the iPython terminal app. Let me know if that seems like a good idea. I didn't do it because I don't like installing extra stuff that I may not use or need?

Anyways, any ideas to why this error is appearing?

EDIT: So I have tried to install the python-dotenv module, but the error still occurs. I tried installing the python-dotenv-run and I may have solved the previous problem, but maybe have another one? The package has the description: "Run command with enviorment populated by the .env file"

Error after installing python-dotenv-run: https://pastebin.com/qtMFRdem

vanilla
  • 69
  • 1
  • 2
  • 13
  • Can you give me the command you used to install it onto your system or the name of the package you installed? e.g. `pip3 install ___` – Kelo Jun 25 '20 at 12:08
  • @Kelo I used `pip3.8 install dotenv` I also tried to instal python-dotenv in terminal possibly and in pycharm but that didnt have any effect at all. Same errors – vanilla Jun 25 '20 at 18:14
  • 1
    Make sure that you're actually using the `python-dotenv` package as that is the only one that includes the `load_dotenv()` function. – Kelo Jun 25 '20 at 20:14
  • 1
    @Kelo Yeah, I tried with the python-dotenv and the `load_dotenv()` didn't work, or in other words wasn't in the module? I looked at the github page and I had no luck. When I ran `pip3.8 install python-dotenv` it installed it to `/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages` Anything I should do with the Pycharm Interpreter or something? Trying other things rn – vanilla Jun 25 '20 at 21:06
  • the solution by @Kelo was the one that worked for me! Thx. – Rui Pires Oct 19 '22 at 11:47

0 Answers0