I have simple code, I am trying to import DAG from airflow
from airflow import DAG
from airflow.operators import BashOperator,S3KeySensor
from datetime import datetime, timedelta
import psycopg2
from datetime import date, timedelta
yesterday = date.today() - timedelta(1)
yesterdayDate = yesterday.strftime('%Y-%m-%d')
But, I am getting Import Error
Traceback (most recent call last):
File "airflow.py", line 9, in <module>
from airflow import DAG
File "/home/ubuntu/airflow/dags/airflow.py", line 9, in <module>
from airflow import DAG
ImportError: cannot import name DAG
apache-airflow version installed 1.9.0
I don't know where I am going wrong
This is similar to Package import failure in Python 3.5
When you name your Python script airflow.py
, the statement from airflow import DAG
ends up trying to import DAG
from the script itself, not the airflow
package.
The lesson is to never name your *.py files the same as built-in modules or 3rd party packages you have installed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With