'Airflow 2 - ModuleNotFoundError: No module named 'airflow.operators.sensors'

After upgrading to Airflow 2, I got that error in some DAGs:

ModuleNotFoundError: No module named 'airflow.operators.sensors'


Solution 1:[1]

The new one that works:

from airflow.sensors.base import BaseSensorOperator

Chosen answer doesn't work for newer versions of Airflow.

Solution 2:[2]

For Airflow 2.1.1 I first installed Amazon provider:

pip install apache-airflow-providers-amazon

and then imported S3KeySensor:

from airflow.providers.amazon.aws.sensors.s3_key import S3KeySensor

Solution 3:[3]

I was trying to import ExternalTaskSensor and my research led me to this post, it turned out to be this class.

The correct import for me was

from airflow.sensors.external_task import ExternalTaskSensor

Just FYI in case anyone runs into this in the future.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrzej Sydor
Solution 2 Andrzej Sydor
Solution 3 Fisher Coder