.env was not load
yc185048 opened this issue · 4 comments
I was going through the example code and found the .env file was not load automatically. I added the following to app_config.py
file
from dotenv import load_dotenv
load_dotenv()
Not sure if it is intended behavior. If not I can create a PR for this. Thanks.
Quoted from Flask's documentation, it should automatically load .env
:
If python-dotenv is installed, running the flask command will set environment variables defined in the files .env
Our sample does use python-dotenv
, and it indeed automatically loads .env
in my environment.
Does that not work for you? Which Flask and python-dotenv versions are you using?
My bad. I start up the app by running python app.py
instead of using python -m flask run
command. It would be good to add extra note for this behavior. Just my though. Thank you!
My bad. I start up the app by running
python app.py
instead of usingpython -m flask run
command. It would be good to add extra note for this behavior. Just my though. Thank you!
We will see what we can improve here. But can you provide more info?
I tried python app.py
and it can still load .env
. I want to reproduce your report in order to get to the bottom of this issue. Which Flask and python-dotenv versions are you using?
Sure. Here are the version info from my pip list
Flask 2.2.5
Flask-Session 0.4.1
python-dotenv 0.21.1
Python 3.10.11
One other thing is I didn't use virtualenv for python env management. I use conda for the python and install package through pip and requirement files.