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

Variable not found ("None" returned) on a Mac #104

Closed
shirki opened this issue Mar 28, 2018 · 18 comments
Closed

Variable not found ("None" returned) on a Mac #104

shirki opened this issue Mar 28, 2018 · 18 comments

Comments

@shirki
Copy link

shirki commented Mar 28, 2018

Hi, we are using dotenv for a project and are getting strange behavior.

While the environment variable is working just fine on a Windows machine, it is not able to read at all on a Mac. It returns "None" even though the variable is clearly there. There seem to be no other issues.

In X.py file:

from dotenv import load_dotenv
load_dotenv()
import os
HOME_PATH = os.getenv("SQUABBLE_HOME_PATH")

In .env file:

SQUABBLE_HOME_PATH = '/path/to/squabble_runner/'

While running:

Traceback (most recent call last):
  File "XXXX/X.py", line 27, in controversy_score
    input_file_path = HOME_PATH + 'lib/squabble_input.txt'
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

This is on Sierra, Python 3.6.2.

As mentioned above, the same code runs just fine on a PC.
Any help would be appreciated!

@devrsw
Copy link

devrsw commented Mar 29, 2018

This is also something we're running into as well.

@TDiazT
Copy link

TDiazT commented Apr 1, 2018

Same as well.

Working on High Sierra, Python 3.5

@shirki
Copy link
Author

shirki commented Apr 4, 2018

@theskumar Several people seem to be having this issue - would really appreciate your help on this one! Thanks in advance.

@theskumar
Copy link
Owner

@shirki can you try providing absolute path to .env file or use find_dotenv() in the call to load_dotenv() see if you are still facing issue?

@theskumar
Copy link
Owner

I've tried running your example on Mac, it works with:

python-dotenv==0.8.2
Python 3.6.4

@garyking
Copy link

garyking commented Apr 7, 2018

I have the same problem as others here. If I use load_dotenv() then it doesn't work. If I use load_dotenv(find_dotenv()) then it works fine though.

@shirki
Copy link
Author

shirki commented Apr 9, 2018

@theskumar Neither load_dotenv(find_dotenv()) nor providing an absolute path worked.

python-dotenv: 0.8.2
Python: 3.6.2
Mac: Sierra

@theskumar
Copy link
Owner

@shirki sorry for the issues you are facing. But I don't seem to able to reproduce the issue. One last time, I would just advice you to use the absolute path to the .env file. It could be file permission issue, but I can't say for sure.

@TDiazT
Copy link

TDiazT commented Apr 9, 2018

I tried running load_dotenv(verbose=True) and I get:

 UserWarning: File doesn't exist 
  warnings.warn("File doesn't exist {}".format(self.dotenv_path))

I tried the other example in the doc:

from pathlib import Path  # python3 only
env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)

which results in

TypeError: argument should be string, bytes or integer, not PosixPath

I str(env_path) to which I still get that the .env file doesn't exist.

I also tried:

from dotenv import load_dotenv
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
env_path = os.path.join(BASE_DIR, '.env')
load_dotenv(dotenv_path=env_path, verbose=True)

but still the same error.

@TDiazT
Copy link

TDiazT commented Apr 9, 2018

Daaaaamn.... I just realised my file was named .env.py !! 😐

Just renamed it to .env and it worked... of course

@theskumar
Copy link
Owner

It happens no worries.

@shirki
Copy link
Author

shirki commented Apr 23, 2018

@theskumar Can you please reopen the issue? I tested it again with python 3.6.5, as well as with an absolute filename or with the load function, and the issue persists. As opposed to @TDiazT, my file name is definitely .env 😄. No file permission issues either.

Let me know what you need from me in order to reproduce the issue. As I mentioned, this is particularly with one mac and one PC on the same team.

@devrsw, are you still getting the same error?

Thanks!

@joarleymoraes
Copy link

joarleymoraes commented May 2, 2018

It happened to me as well on Docker/Ubuntu14.04. I had to explicitly load with dotenv_path:

from dotenv import load_dotenv
load_dotenv(dotenv_path='.env', verbose=True)

@ccennis
Copy link

ccennis commented May 18, 2018

i'm on a mac, high sierra and I had the same issue until I changed it to:

from dotenv import load_dotenv
from dotenv import find_dotenv
load_dotenv(find_dotenv())

@yashg5
Copy link

yashg5 commented Sep 28, 2018

This solved my issue:
from dotenv import load_dotenv
from dotenv import find_dotenv
load_dotenv(dotenv_path=find_dotenv(), verbose=True)

@kashaziz
Copy link

I had similar issue on Python 3.5 (working fine on later versions). What worked for me is using explicit path to .env. Assuming the env file is in projects folder, it can be loaded as follows:

load_dotenv(os.path.join(BASE_DIR, "backend", ".env"))

@andhint
Copy link

andhint commented Jul 16, 2020

I had similar issues where adding the path or find_dotenv() didn't work. I recreated my .env file to be sure it had the right extension and that fixed it. I'm guessing I messed something up creating the .env the first time somehow.

@KaeganCasey
Copy link

Saw this issue and wanted to post what worked for me since none of the above fixes were working for my problem.

I had trouble getting python-dotenv to work because I had jupyterlab installed in my conda (miniforge) base environment and had installed python-dotenv in a separate environment. python-dotenv wasn't recognizing the .env file correctly from jupyterlab and after a lot of trouble shooting all I had to do was install python-dotenv in my base conda env as well. Then load_dotenv() correctly recognized my .env file in the same folder as my notebook.

Just wanted to post in case someone else had the same problem.

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