Importing Local Module (Python Script) in Airflow Dag

How to import external scripts in a Airflow DAG with Python?

I needed insert the following script inside at the top of ren.py :

import sys, os
from airflow.models import Variable

DAGBAGS_DIR = Variable.get('DAGBAGS_DIR')
sys.path.append(DAGBAGS_DIR + '/bi/inbound_layer/')

This way I make available the current folder packages.

Apache Airflow DAG cannot import local module

Adding the sys path again worked for me,

import sys
sys.path.insert(0,os.path.abspath(os.path.dirname(__file__)))


Related Topics



Leave a reply



Submit