Python3 ModuleNotFoundError: No module named 'dotenv'

716 views Asked by At

I'm getting ModuleNotFoundError: No module named 'dotenv' error. I did install python-dotenv as suggested in other posts but it still gives error. How to fix it?

My code

import os
import json

import openai
import pandas as pd

from dotenv import load_dotenv

load_dotenv()
...

Error

(.venv) ~/ROOT/Python/finetunechat/openai $ pip list | grep dotenv
    python-dotenv 0.21.1
    (.venv) ~/ROOT/Python/finetunechat/openai $ python 1.py
    Traceback (most recent call last):
      File "1.py", line 7, in <module>
        from dotenv import load_dotenv
    ModuleNotFoundError: No module named 'dotenv'
    (.venv) ~/ROOT/Python/finetunechat/openai $ 
1

There are 1 answers

0
Jaden Scali On BEST ANSWER

Make sure it's installed in the same virtual environment (venv) as your project

pip install python-dotenv

Before running that command ensure your venv is live by running:

For Mac/Linux

source .venv/bin/activate

For Windows

.venv\Scripts\activate

Also try reopening the project after installing

Hope this helps!