question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

If using a .env file with Docker, the Flask CLI still tells you to install python-dotenv

See original GitHub issue

If 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:

image

Environment

  • Python version: 3.9.1
  • Flask version: 1.1.2
  • Werkzeug version: 1.0.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
nickjjcommented, Jan 18, 2021

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 add FLASK_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:

Ah, you’re right, the cli in general checks for the file. I’m not going to remove the message right now

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 using flask 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.

0reactions
davidismcommented, Jan 18, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found