Search code examples
pythonlinuxconfigurationyamlfb-hydra

Get system environment variable when using Hydra


I want to access an environment variable through .yaml when I use Hydra like below, but it gives me an error.

system_env1:   ${SYS_ENV_1}

I have also tried unsuccessfully:

system_env1:   $SYS_ENV_1

I don't want to get the variable in through python code. It should be retrieved through the .yaml interface.


Solution

  • If you want to access an environment variable in hydra, fall back to omegaconf's resolver oc.env which also works in hydra.

    system_env1:   ${oc.env:SYS_ENV_1}