Can't import Airflow plugins

Christopher Carlson picture Christopher Carlson · May 11, 2017 · Viewed 27k times · Source

Following Airflow tutorial here.

Problem: The webserver returns the following error

Broken DAG: [/usr/local/airflow/dags/test_operator.py] cannot import name 
MyFirstOperator

Notes: The directory structure looks like this:

airflow_home
├── airflow.cfg
├── airflow.db
├── dags
│   └── test_operators.py  
├── plugins
│   └── my_operators.py   
└── unittests.cfg

I am attempting to import the plugin in 'test_operators.py' like this:

from airflow.operators import MyFirstOperator

The code is all the same as what is found in the tutorial.

Answer

Sneha K picture Sneha K · Jan 4, 2019

I use airflow 1.10. If it's a custom operator that you want to import, you can upload it to the airflow plugins folder, and then in the DAG specify the import as :

from [filename] import [classname]

where : filename is the name of your plugin file classname is the name of your class.

For example : If the name of your file is my_first_plugin and name of the class is MyFirstOperator then, the import would be :

from my_first_plugin import MyFirstOperator

Worked for me as I am using airflow 1.10

Thanks ! Hope this helps !!