I’m trying to install the module dotenv cause it is used on the code that gives acces to the API of OpenAI, but it doesn’t work, it says to me that there is an error.
So how can i do ?
Note: I’m using PyCharm (IDE)
You posted in the “General Discussions” area.
I’ll move your thread to the area for the ChatGPT course.
Perhaps a mentor or community member for that course will find it and reply.
There are many ways to do this, but this is how I set it up.
Do you have the package installed? If not, install it.
pip install python-dotenv
Then create a .env file in project root with this contents:
OPENAI_API_KEY=your_key_here
Then create a settings.py in project root with this code:
import os
from os.path import join, dirname
from dotenv import load_dotenv
dotenv_path = join(dirname(file), ‘.env’)
load_dotenv(dotenv_path)
OPENAI_API_KEY = os.environ.get(“OPENAI_API_KEY”)
Usage in any python file:
import settings as s
def test():
response = s.OPENAI_API_KEY
return response
output = test()
print("OPEN API KEY is: ", output)
Now, it is saying that it doesn’t found the commands load_dotenv and find_dotenv in the modul dotenv
I had to “pip install python-dotenv” for this to work.