You cannot do what you want. The os.getenv
cannot get variables straight from the .env
file.
TLDR;
Regarding the setting of the env vars:
In macOS to set the env var temporarily:
export [variable_name]=[variable_value]
To do it permanently:
- open
~/.bash-profile
- scroll down to the end of the .bash_profile file
- add
export [variable_name]=[variable_value]
at the end of it
- save any changes you made to the
.bash_profile
file
- execute the new
.bash_profile
by either restarting the terminal window or using source ~/.bash-profile
If you don't want to use the mentioned dotenv
library you'll have to source the .env file first and export all the variables before running your python script which uses os.getenv
, see this: https://stackoverflow.com/a/65694371/15923186