AttributeError: ‘module’ object has no attribute ‘load_dotenv

今天药忘吃喽~ 2022-05-29 05:56 284阅读 0赞

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.

发表评论

表情:
评论列表 (有 0 条评论,284人围观)

还没有评论,来说两句吧...

相关阅读