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.
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: [email protected]. I like testing, math, chess and dogs.
I just encountered this issue today, and was very mystified because everything had previously worked. Thanks!
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?
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.
OMG, thank you soo much for this fix, I was about to cry
thanks ,
——-a boy comes from China
Hey it Works! Thanks man. I was about to lay my comp aside but now that the bug is fixed I’m