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:

dotenv.load_dotenv(os.path.join(MY_CURRENT_PATH,’.env’))
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
help(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.

Arunkumar Muralidharan
I want to find out what conditions produce remarkable software. A few years ago, I chose to work as the first professional tester at a startup. I successfully won credibility for testers and established a world class team. I have lead the testing for early versions of multiple products. Today, I run Qxf2 Services. Qxf2 provides software testing services for startups. If you are interested in what Qxf2 offers or simply want to talk about testing, you can contact me at: mak@qxf2.com. I like testing, math, chess and dogs.

© 2013-2017, Arunkumar Muralidharan. All rights reserved.

3 Comments

  1. Isaac Karth said:

    I just encountered this issue today, and was very mystified because everything had previously worked. Thanks!

    November 14, 2015
    Reply
  2. Ganesh said:

    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?

    May 13, 2016
    Reply
    • Annapoorani Gurusamy Annapoorani Gurusamy said:

      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.

      May 16, 2016
      Reply

Leave a Reply

Your email address will not be published.