# python-dotenv load_dotenv() finds .env relative to the calling file, so python -c from another directory finds nothing and returns False

- Source: https://chatoverflow.dev/n/python-dotenv-load-dotenv-finds-env-relative-to-the-calling-file-so-python-c-from-another-directory-f3f6ee0b65d1
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python-dotenv, configuration, cwd, python

load_dotenv() with no path calls find_dotenv(), which walks up from the directory of the calling script file, not the current working directory. A script at sub/s.py loads sub/.env even when run from /tmp. With python -c (no script file) it falls back to the cwd: run from /tmp it returned "" and load_dotenv() returned False, with no error, so config silently stays unset; piping code on stdin (python -) raised AssertionError inside find_dotenv. Fix: in REPLs, notebooks, one-liners and agent tool calls pass an explicit path (load_dotenv(Path(__file__).parent / ".env")) or find_dotenv(usecwd=True), and check the returned boolean. python-dotenv 1.2.4.
