Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: cannot import name load_dotenv #6

Closed
sirvon opened this issue Jul 30, 2015 · 34 comments
Closed

ImportError: cannot import name load_dotenv #6

sirvon opened this issue Jul 30, 2015 · 34 comments

Comments

@sirvon
Copy link

sirvon commented Jul 30, 2015

I've been getting this error on a python 2.7 installation:

ImportError: cannot import name load_dotenv

any word on what gives?

@aniketmaithani
Copy link

@sirvon well make sure you have activated your virtualenv if you are using this inside it.

@theskumar
Copy link
Owner

@sirvon Please re-open this issue if the above solution doesn't work for you. Make sure, you have installed python dotenv and/or activated virtualenv.

@cnicodeme
Copy link

The issue is still present even in Debian Jessie. Please re-open it.

@cnicodeme
Copy link

Ok for future peoples that get here, the load_dotenv has been removed.

Do this instead :

import os
from dotenv import Dotenv
dotenv = Dotenv(os.path.join(os.path.dirname(__file__), ".env")) # Of course, replace by your correct path
os.environ.update(dotenv)

@saurabh-fueled
Copy link

@cnicodeme that's kind of strange as Dotenv was never part of this library. Are you sure, the library that you are using is python-dotenv and not something else.

It would really helpful if you can post the output of your pip freeze command and/or

import dotenv
print dir(dotenv)

Thanks,

@cnicodeme
Copy link

Yes of course,

But I'm also suspecting it's not the same "dotenv"? I installed it using pip install dotenv.

Here's the print dir(dotenv) result :
['Dotenv', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', 'get_variable', 'get_variables', 'set_variable', 'with_statement']

And the pip freeze for dotenv :
dotenv==0.0.5

@saurabh-fueled
Copy link

@cnicodeme the correct install command is:

pip install python-dotenv

You can simply fix this by

pip uninstall dotenv
pip install python-dotenv

Let me know if that helps!

Cheers!

@cnicodeme
Copy link

Thank you.

I already fixed my issue by doing what I indicated before (my second comment).

Cheers :)

@saurabh-fueled
Copy link

@sirvon
Copy link
Author

sirvon commented Jun 3, 2016

why isnt this working on mac os el cap....
i forgot how i got this to work...

    from dotenv import load_dotenv
ImportError: cannot import name 'load_dotenv'

@waltertschwe
Copy link

I think this has changed again... has changed from "load_dotenv" to "load"
so you would need to do this :

dotenv_path = join(dirname(__file__), '.env')
load(dotenv_path)

@theskumar
Copy link
Owner

hi @waltertschwe, it has always been the same.

I would suggest you run the following and see what's the output:

import dotenv
print dir(dotenv)

there is a high chance of library mismatch.

@MohamedAlaa
Copy link

Hi @theskumar

I'm getting this error whenever i try to import dotenv:

>>> import dotenv Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.7/site-packages/dotenv/__init__.py", line 1, in <module> from .cli import get_cli_string File "/usr/local/lib/python2.7/site-packages/dotenv/cli.py", line 3, in <module> import click ImportError: No module named click

@undefinedplayer
Copy link

After uninstall dotenv, for my case it still didn't work. However, it works after I reinstall python-dotenv.

pip uninstall dotenv
pip uninstall python-dotenv
pip install python-dotenv

@jmrr
Copy link

jmrr commented Mar 14, 2017

@shlinx solution of uninstalling dotenv and python-dotenv and then reinstalling python-dotenv works.

However, tools like pipreqs recognise the package as dotenv if not installed, and python_dotenv AND dotenv if installed. pip freeze discovers the dependency as python-dotenv.

What can be the long term solution?

@shaunakmukherjee
Copy link

Hey, I'm having a similar issue on an Ubuntu 16.04. The pip freeze command didn't help, and there's still an error saying that it can't import the 'load_dotenv'. Any ideas?
@theskumar could you give an insight?

@theskumar
Copy link
Owner

@shaunakmukherjee try uninstalling and installing pip install python-dotenv.

Best option would be to create and try inside a virtualenv.

@shaunakmukherjee
Copy link

shaunakmukherjee commented Apr 13, 2017

@theskumar have already done them, as the picture shows.
Still not happening.

load_dotenv

@theskumar
Copy link
Owner

Try in the python manage.py shell.

import dotenv
dir(dotenv)

what do you see?

@shaunakmukherjee
Copy link

['Dotenv', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', 'get_variable', 'get_variables', 'set_variable', 'with_statement']

@theskumar
Copy link
Owner

@shaunakmukherjee you have dotenv installed which is not python-dotenv you need to uninstall it first. see: #6 (comment)

@shaunakmukherjee
Copy link

shaunakmukherjee commented Apr 13, 2017

Well, I have python-dotenv installed as well. pip freeze shows a version of python-dotenv.
@theskumar

@theist
Copy link

theist commented Apr 24, 2017

Well, I have python-dotenv installed as well.

@shaunakmukherjee It seems that having python-dotenv and dotenv packages causes issues... I had the two installed and run into the same issue. I fixed it uninstalling dotenv and leaving python-dotenv instaled

@ltfschoen
Copy link

ltfschoen commented May 1, 2017

I also got the error ImportError: cannot import name load_dotenv when using Python 3.6 after installing https://github.com/theskumar/python-dotenv version 0.6.4 to with pip install python_dotenv.

I gave up and tried https://github.com/mattseymour/python-env version 1.0.0 instead, which I installed with pip install python-env. I used it in my file as follows, and it worked successfully without any issues:

import os
import dotenv

# output of the following command should be: `['__author__', '__builtins__', '__cached__', ...`
print("dotenv should be shown here: ", dir(dotenv))

APP_ROOT = os.path.join(os.path.dirname(__file__), '')
dotenv_path = os.path.join(APP_ROOT, '.env')
dotenv.load(dotenv_path)
fb_page_token = os.getenv('FACEBOOK_PAGE_TOKEN')

@djdeo
Copy link

djdeo commented Mar 23, 2018

Traceback (most recent call last):
File "manage.py", line 9, in
dotenv.read_dotenv()
AttributeError: module 'dotenv' has no attribute 'read_dotenv'

after pip install python_dotenv

@theskumar
Copy link
Owner

@djdeo read_dotenv() is not part of this library, make sure you have installed the correct requirement, there are other dotenv python libraries as well.

@djdeo
Copy link

djdeo commented Mar 24, 2018

@theskumar thanks, I tried pip install django_dotenv and it worked

@lexsoul
Copy link

lexsoul commented Nov 13, 2018

sudo apt install python3-dotenv
worked for me in a Hyper-V virtual machine with Ubuntu 18.04

@tumispro
Copy link

@ltfschoen thanks, couldn't get the other package to work on MacOS Mojave either, that one worked perfectly!

@Prajwalprakash3722
Copy link

Uninstall dotenv and python-dotenv sudo pip uninstall dotenv && sudo pip uninstall python-dotenv
then install the python-dotenv sudo pip install python-dotenv

This really works

@felipeabou
Copy link

This is still happening. It's so annoying. No solution yet?

@RT-Tap
Copy link

RT-Tap commented Jan 29, 2022

I'm having this issue as well ... never installed dotenv only python-dotenv ... Getting ImportError: cannot import name 'Dotenv' from partially initialized module 'dotenv' (most likely due to a circular import) (C:\Users\me\source\python\myapp\dotenv.py)
Tried from dotenv import load_dotenv and from dotenv import Dotenv as well as any other solutions I could find on stackoverflow and in this thread

@atheeralattar
Copy link

@RT-Tap Change your .py file name

@matiasvallejosdev
Copy link

Thanks! 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests