我有简单的代码,我正试图从气流导入DAG
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')
但是,我收到导入错误
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版本安装1.9.0
我不知道我哪里出错了
答案 0 :(得分:6)
这类似于Package import failure in Python 3.5
当您命名Python脚本airflow.py
时,语句from airflow import DAG
最终会尝试从脚本本身导入DAG
,而不是airflow
包。
本课程绝不会将您的Python脚本称为与已安装的内置模块或第三方pacakges相同。