AttributeError: ‘module’ object has no attribute ‘load_dotenv’

I needed to use the dotenv module in Python. I tried the usual

pip install dotenv

Wohoo! I was able to import dotenv without any trouble. It was easy enough to install. Python is so intuitive, right? Well, not in this one case. When I ran my script, I kept getting the error:

AttributeError: ‘module’ object has no attribute ‘load_dotenv’

Eh? dotenv imports fine. So what could the issue be? I launched the Python interpreter and did

import dotenv

Turns out that the dotenv module did not have a load_dotenv method. A little bit of Googling shows that there is another python-dotenv package that also installs the dotenv module. Not cool, Python! So to get past my error, I uninstalled the seemingly intuitive dotenv package and then installed the python-dotenv.

pip uninstall dotenv
pip install python-dotenv

And now my script works.

6 thoughts on “AttributeError: ‘module’ object has no attribute ‘load_dotenv’

  1. Another way I found out when I got the error dot env module not found, is by downloading the tar for dotenv from python website—>untar–>copy the dotenv folder and drop to Libs folder —> is that one of the right ways?

    Note: I tried the one you have specified above but no luck hence used that approach. Thought it might be useful if it turns out to be a good approach?

    1. Hi Ganesh,The better way to install dotenv is by using pip. Pip is a convenient way to install, upgrade and uninstall modules. You need to manually perform the install, upgrade and uninstall if you use tar files.

Leave a Reply

Your email address will not be published.