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

Readme WSGI example doesn't find the correct folder #39

Open
checor opened this issue Aug 19, 2019 · 1 comment
Open

Readme WSGI example doesn't find the correct folder #39

checor opened this issue Aug 19, 2019 · 1 comment

Comments

@checor
Copy link

checor commented Aug 19, 2019

Hello,

Trying to run the WSGI example on readme doesn't work when runned in any other folder than the one the .env lives.

For example, having a folder with a .env a file named main.py:

import os
import dotenv

print("Loading file:", os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env'))
dotenv.read_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env'))

Running on the same folder works without problems:

$ python main.py
Loading file: .env

Moving to another folder, fails:

$ python path/to/main.py
Loading file: .env
dot_env_example/main.py:5: UserWarning: Not reading .env - it doesn't exist.
  dotenv.read_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env'))

This can be avoided removing the duplicated os.path.dirname part:

 $ python path/to/main.py
Loading file: path/to/.env

Is the parameter supposed to be entered relative to the main.py folder, or relative to the folder being run?

Cheers!

@lizkepner
Copy link

I just ran into this issue in my own environment.

Changing
dotenv.read_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), '.env'))

to
dotenv.read_dotenv(os.path.join((os.path.dirname(__file__), '.env'))

is what fixed the problem for me.

Hope this helps!

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

2 participants