If using a .env file with Docker, the Flask CLI still tells you to install python-dotenv
See original GitHub issueIf you have a .env
file and are using Docker you don’t need to install python-dotenv
.
But every time you run any flask
CLI command, Flask will output * Tip: There are .env or .flaskenv files present. Do "pip install python-dotenv" to use them.
to stdout before any other output.
Perhaps this tip could be removed all together? IMO if you’re using env files you likely already know to use python-dotenv
and if you’re using Docker you have access to your environment variables through other means.
Expected Behavior
No tip output to be present.
Actual Behavior
It produces this:
Environment
- Python version: 3.9.1
- Flask version: 1.1.2
- Werkzeug version: 1.0.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
I have installed python-dotenv but python cannot find it
When starting flask it sees there are some .env files and tells me to install dotenv even though it is installed and i...
Read more >python-dotenv prevents launch of Flask server #271 - GitHub
If python -dotenv is installed, running the flask command will set environment variables defined in the files .env and .flaskenv.
Read more >Automatically Load Environment Variables in Flask
In this article, I'll show you how to use python-dotenv to have your environment variables loaded and ready to go every time you...
Read more >Python-dotenv (Keep your secrets safe) - DEV Community
In this article, i am going to guide you on how to work with SECRETS and KEYS without exposing them to the outside...
Read more >Using Environment Variables in Python for App Configuration ...
Here are some examples of using environment variables to configure a Python script or application: Set FLASK_ENV environment variable to " ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sure it can be automated in development, but it means setting it in every project and in production chances are you’re not committing your
.env
which means you need to explicitly addFLASK_SKIP_DOTENV=true
to whatever production environment you’re deploying to.That could be adding it through the Heroku CLI or editing whatever env variables / env file / secrets mechanism you use with Docker Compose, systemd, Kubernetes, ECS, Swarm, DigitalOcean Apps or the half dozen other application runtimes that all load env variables in various ways without needing
python-dotenv
.Edit:
The only reason I’m pushing back on this is because it’s an inconvenience to every person running Flask in production since the tip comes up every time you run any
flask
command.If it worked as you originally described by only being output with
flask run
then it would be no big deal since no one would ever see it unless you were in development usingflask run
. But since we determined it’s a bug and not working like that, maybe as a compromise you can make the warning only show up in the case you originally intended it for? That solves the problem too.Ah, you’re right, the cli in general checks for the file. I’m not going to remove the message right now, so your best bet is setting the extra environment variable. You could automate this if you use something like cookiecutter to create new projects from templates.