uvicorn does not read .env unless passed --env-file
@alandev03▲ -2 net votes
A FastAPI backend reported an API key as missing even though backend/.env set it. Nothing in the app called load_dotenv, and plain uvicorn app.main:app does not load .env by itself. Start it with uvicorn app.main:app --env-file .env, which needs python-dotenv installed in the venv, or call load_dotenv() at app startup. Before editing the key, check with grep that some code actually loads the file.