【发布时间】:2020-05-15 15:41:33
【问题描述】:
我已将自己的包添加到 /usr/local/lib/python3.7/site-packages(在 sys.path 中):
一些包 初始化.py 助手.py
以下 DAG 位于 /usr/local/airflow/dags/dev
import sys
print(sys.path)
import somepackage.helper as nf
print(nf.__file__)
import numpy as np
print(np.sqrt(2))
import datetime as dt
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.operators.python_operator import PythonOperator
stage = 'dev'
# An usual python method which can be executed:
def print_world():
print('world')
# Meta informations for airflow:
default_args = {
'owner': f'{stage}',
'start_date': dt.datetime(2020,2,13),
'retries': 1,
'retry_delay': dt.timedelta(minutes=5),
'queue': stage
}
# The definition and 'script' of the DAG:
with DAG(f'test_{stage}',
default_args=default_args,
schedule_interval=None) as dag:
# Define the steps in the pipeline, see airflow docs for more operators:
print_hello = BashOperator(task_id='print_hello', bash_command='echo "hello"')
print_world = PythonOperator(task_id='print_world', python_callable=print_world)
makefile = BashOperator(task_id='makefile', bash_command='touch /usr/local/airflow/dags/justToTest.txt')
# Pipeline: first do x then do y then do z ....
print_hello >> print_world >> makefile
我可以在 Web UI 中看到该文件,并在日志中看到所有打印语句。然而,Airflow 在 Web UI 中一直说在读取的标头中找不到该模块。
【问题讨论】:
-
[1] 你有 dockerized 部署吗? [2] 您是否在使用某种 Python 虚拟环境? [3] 您是否使用
SequentialExecutor或LocalExecutor以外的执行程序? 很可能,您的自定义模块不在您的webserver进程的PYTHONPATH上 -
[1]是的,它是 puckel/docker-airflow 并且在 Dockerfile 中我已将我的模块添加到站点包目录中。 [2] 我正在使用 CeleryExecutor。 [3] 如果我在 DAG 中打印 sys.path,我可以在日志中看到 site-packages 路径是列表的一部分
标签: airflow