'DAG import error because ModuleNotFoundError
I recently upgraded from Airflow 1.10.15 to 2.2.4. Installed using sudo. Upgraded the DB after the upgrade. Airflow is running but there are import errors.
I have multiple DAGs with the line from airflow.operators.mssql_operator import MsSqlOperator but I am getting the following error once the scheduler and webserver are up:
Broken DAG: [/opt/airflow/dags/admissions.py] Traceback (most recent call last):
File "/opt/airflow/dags/admissions.py", line 7, in <module>
from airflow.operators.mssql_operator import MsSqlOperator
File "/usr/local/lib/python3.6/dist-packages/airflow/operators/mssql_operator.py", line 22, in <module>
from airflow.providers.microsoft.mssql.operators.mssql import MsSqlOperator # noqa
ModuleNotFoundError: No module named 'airflow.providers.microsoft.mssql.operators'
Additional information about providers:
apache-airflow-providers-ftp | 2.1.0
apache-airflow-providers-http | 2.1.0
apache-airflow-providers-imap | 2.2.1
apache-airflow-providers-microsoft-mssql | 2.1.1
apache-airflow-providers-odbc | 2.0.2
apache-airflow-providers-sqlite | 2.1.1
How do I resolve this?
Solution 1:[1]
It seems like you do have the correct provider's package (apache-airflow-providers-microsoft-mssql)
But, you are using the "old form" import instead of the new one
Please try to changefrom airflow.operators.mssql_operator import MsSqlOperator
tofrom airflow.providers.microsoft.mssql.operators.mssql import MsSqlOperator
Some links to API reference and small tutorial:
https://airflow.apache.org/docs/apache-airflow-providers-microsoft-mssql/stable/_api/airflow/providers/microsoft/mssql/operators/mssql/index.html#module-airflow.providers.microsoft.mssql.operators.mssql
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 | Saar Levy |
