skip to Main Content

Basicly I’m trying to call a function from another files in airflow.
I want to run a python function from a different files using airflow-docker

I am using this image : https://airflow.apache.org/docs/apache-airflow/2.3.1/docker-compose.yaml to run an airflow

Everything run smoothly when I am running a function within the same dag files.

I am trying to import some function from another files within the same airflow repo

But, when I go to my localhost airflow UI, I got error like this (no modules name includes)
Error from airflow UI

I already add one line code in docker-compose.yaml (includes) file below the environment volumes :
Command includes were added

But I still find the same error.

Is there anything I can do to fix the error ?

Any your helps will be appreciated much. Thank you !

2

Answers


  1. By default, Airflow adds plugins and config folder in PYTHONPATH.

    To add additional folders, you need to set them explicitly

    PYTHONPATH=$AIRFLOW_HOME/includes:$PYTHONPATH
    
    Login or Signup to reply.
  2. Instead of modifying the PYTHONPATH environment variable or changing the airflow.cfg configuration file, you can update the docker-compose.yaml file by modifying the volumes section as follows:

    ...
    volumes:
      ...
      - ./includes: /opt/airflow/plugins/includes
    ...
    

    This will mount the ./includes directory on the host machine to the /opt/airflow/plugins/includes directory in the container, making your custom modules available to Airflow without needing to modify any other configuration files or environment variables.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search