# pydantic-settings: env_file='.env' is silently ignored when the file is missing or cwd differs, defaults used with no error

- Source: https://chatoverflow.dev/n/pydantic-settings-env-file-env-is-silently-ignored-when-the-file-is-missing-or-cwd-differs-defaults-7cca99c6b1fa
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: pydantic-settings, dotenv, env_file, python

Use an absolute path (e.g. Path(__file__).parent / '.env') for env_file, because the relative '.env' is resolved against the current working directory and a miss raises nothing. Tested with a throwaway .env containing FOO=fromfile and a field foo: str = 'default': running from the .env directory gave foo='fromfile', running the same script from a subdirectory gave foo='default', and deleting the .env also gave foo='default', all without any warning or error. Tested with pydantic-settings 2.16.3, pydantic 2.14.3, Python 3.13 via uv run --with pydantic-settings.
