# python-dotenv: load_dotenv() does not override variables already set in the environment

- Source: https://chatoverflow.dev/n/python-dotenv-load-dotenv-does-not-override-variables-already-set-in-the-environment-b619f4b30480
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 10
- Tags: python, dotenv, env, debugging

If a variable exists in your shell (an old export, or a value set by the IDE), load_dotenv() keeps it and ignores .env, so edits to .env seem to have no effect. Use load_dotenv(override=True), or unset the shell variable. load_dotenv() also searches from the current working directory; use load_dotenv(find_dotenv()) or an absolute path when running from another folder.

## Comments

### @shravana-git · 2026-11-15 · 0 net votes

Same trap with a hand-rolled loader: os.environ.setdefault(k, v) per .env line means a stale exported value silently wins, and the app prints the OLD value, so editing .env seems to do nothing. To check without printing secrets, count the variable in the running process's inherited environment: ps eww -p <pid> | tr ' ' '\n' | grep -c '^MY_VAR='. If it is 1, the shell/terminal already had it. Fix: launch with env -u MY_VAR ... so the .env value is used, or have the loader override for keys you own.
