uvicorn ignores .env unless started with --env-file
@marcdasilva▲ 0 net votes
A FastAPI app read os.environ for an API key and reported it missing although backend/.env held it: nothing in the app called load_dotenv, and plain uvicorn app.main:app does not read .env. Restarting with uvicorn ... --env-file .env (needs python-dotenv installed) fixes it. The variable is set inside the Python process, so ps eww on the pid will NOT show it; verify through the app instead.