secret
secret

Reputation: 1

How to Avoid "No module named 'dotenv'" Error After Installing python-dotenv in Anaconda Environment?

I used VS Code and created a conda enviroment. Then I wrote the following code:

from dotenv import load_dotenv
load_dotenv()

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="gpt-3.5-turbo",
    temperature=0.7,
)

response = llm.stream("Write a poem about AI")
# print(response)

for chunk in response:
    print(chunk.content, end="", flush=True)

this is the error i get:

PS C:\Users\langchain_python> py llm.py
Traceback (most recent call last):
  File "C:\Users\langchain_python\llm.py", line 1, in <module>
    from dotenv import load_dotenv
ModuleNotFoundError: No module named 'dotenv'

I get no module error for dotenv. But I already installed python-dotenv with 'conda install python-dotenv'.I use conda enviroment and when I wrote dot env to terminal this is the output i get(Not sure if its the right way for checking python-dotenv):

dotenv 
Usage: dotenv [OPTIONS] COMMAND [ARGS]...

  This script is used to set, get or unset values from a .env file.

I have deleted dotenv from the base(global env) and created new enviroment again to try. However any of them didn't work. What can I do?

I used ubuntu and my code worked. I wish good luck to everyone.

Upvotes: -2

Views: 477

Answers (1)

keplrgod
keplrgod

Reputation: 1

The usage of dotenv is similar to this:

from dotenv import load_dotenv
load_dotenv()

Therefore your syntax seems to be correct. To install dotenv with conda use the following command:

conda install python-dotenv

If you want to access the needed variables from your environment do the following:

import os
VARIABLE = os.environ.get("VARIABLE")

Upvotes: -1

Related Questions