【问题标题】:Airflow Broken DAG: no module named somepackageAirflow Broken DAG:没有名为 somepackage 的模块
【发布时间】: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] 您是否使用SequentialExecutorLocalExecutor 以外的执行程序? 很可能,您的自定义模块不在您的 webserver 进程的 PYTHONPATH
  • [1]是的,它是 puckel/docker-airflow 并且在 Dockerfile 中我已将我的模块添加到站点包目录中。 [2] 我正在使用 CeleryExecutor。 [3] 如果我在 DAG 中打印 sys.path,我可以在日志中看到 site-packages 路径是列表的一部分

标签: airflow


【解决方案1】:

这很简单:其他服务(worker,..)没有获得正确的 docker 镜像。该软件包在那里丢失,仅在网络服务器服务中可用。

【讨论】:

  • 那么你是怎么把dags推给工人的?
  • 我不明白,你能解释一下吗?
  • 代码在 worker 上执行,并且该容器缺少依赖项
  • 我认为这只是意味着在您的容器中安装缺少的软件包,而不是在本地安装。
猜你喜欢
  • 2022-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-01
  • 1970-01-01
  • 2022-10-01
  • 1970-01-01
  • 2019-09-19
相关资源
最近更新 更多