Am having trouble loading a .env file using python-dotenv within Prefect.
Within
Deployment.build_from_flow
, am setting
is_schedule_active=ENV == "production"
based upon whether the env is production, or not. This is determined by an import from another file:
from common.config import ENV
and in that file is:
# have also tried dotenv.find_dotenv() without success
dotenv_path = os.path.abspath(os.path.join(__file__, "../../../.env"))
if not os.path.isfile(dotenv_path):
raise RuntimeError(dotenv_path)
This loads happily in a local ipython shell. But when run as a prefect flow, the folder structure appears to be different:
Flow could not be retrieved from deployment.
Traceback (most recent call last):
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/private/var/folders/d8/sqvg_pms3pd0xvcl2tvvxhqr0000gn/T/tmp8e6a8h47prefect/prefect_daily_internal_metric.py", line 9, in <module>
from common.config import ENV
File "/private/var/folders/d8/sqvg_pms3pd0xvcl2tvvxhqr0000gn/T/tmp8e6a8h47prefect/common/config.py", line 9, in <module>
raise RuntimeError(dotenv_path)
RuntimeError: /private/var/folders/d8/sqvg_pms3pd0xvcl2tvvxhqr0000gn/T/.env