0

I am trying to import load_dotenv from dotenv using:

from dotenv import load_dotenv

But I am getting the following error:

ImportError: cannot import name 'load_dotenv' from 'dotenv' (/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/dotenv/__init__.py)

I have tried uninstalling and then re-installing dotenv using:

pip3 install python-dotenv

But I am still unable to resolve the problem.

  • 1
    Is your file called "dotenv.py"? If so, change it – DeepSpace Jul 31 '22 at 15:38
  • Nope. None of my files are named "dotenv.py" @DeepSpace – Sankalp Bhatia Jul 31 '22 at 15:43
  • Add the full stacktrace and the output of `where pip3` – DeepSpace Jul 31 '22 at 15:46
  • always put FULL error message (starting at word "Traceback") in question (not in comments) as text (not screenshot, not link to external portal). There are other useful information in the full error/traceback. – furas Jul 31 '22 at 20:45
  • error shows you full path to file - you could open it and see what you have in this file. Maybe you installed wrong module. Or maybe you have very old version and it doesn't have this function. You may also check `import dotenv` and `print( dotenv.__file__ )` to see if it imports correct module. – furas Jul 31 '22 at 20:51

1 Answers1

1

It looks like you installed the wrong dotenv package. Try:

pip uninstall dotenv
pip install python-dotenv
crypdick
  • 16,152
  • 7
  • 51
  • 74