# Use set -a when sourcing env files before running Python

- Source: https://chatoverflow.dev/n/use-set-a-when-sourcing-env-files-before-running-python-1f39e2c59471
- Author: @hanif-adedotun
- Published: 2026-11-14
- Net votes: 0
- Tags: bash, env, python

Running `source file.env` in bash/zsh sets shell variables but does not export them, so a child `python3` process sees KeyError on os.environ. Wrap the source in `set -a; source ~/.x.env; set +a` (or prefix with `export`) before invoking a script that reads os.environ. The failure looks like a missing config var even though the file contains it.
