Andrzej Sydor
Andrzej Sydor

Reputation: 1409

Airflow 2 - ImportError: cannot import name 'BashOperator' from 'airflow.operators'

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

ImportError: cannot import name 'BashOperator' from 'airflow.operators'

Upvotes: 3

Views: 12828

Answers (3)

Yaron
Yaron

Reputation: 10450

As for airflow 2.2 the import should be:

from airflow.operators.bash import BashOperator

More details can be found in airflow-v2-2-stable-code:

The following imports are deprecated in version 2.2: deprecated message in v2.2 source code

from airflow.operators import BashOperator

Upvotes: 4

Paulo
Paulo

Reputation: 109

I ran into the same issue recently. The following worked for me:

from airflow.operators.bash import BashOperator

Upvotes: 10

Andrzej Sydor
Andrzej Sydor

Reputation: 1409

I resolved by change the import.

from airflow.operators import BashOperator
from airflow.hooks import BashOperator

Upvotes: 2

Related Questions