gpt4 book ai didi

python - Airflow - ModuleNotFoundError : No module named 'kubernetes'

转载 作者:行者123 更新时间:2023-12-02 11:53:48 25 4
gpt4 key购买 nike

我在我的机器上安装了 Python、Docker 并尝试导入from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator但是当我连接 docker 时,我收到模块不存在的消息。我已经完成了pip install apache-airflow[kubernetes]我仍然有同样的错误。是否有特定的机器位置我应该检查库是否实际安装?我能做些什么来解决这个问题?

enter image description here

from airflow import DAG
from datetime import datetime, timedelta
from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator
from airflow.operators.dummy_operator import DummyOperator
import logging
import os
from airflow.utils.helpers import parse_template_string

default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime.utcnow(),
'email': ['airflow@example.com'],
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5)
}

dag = DAG(
'kubernetes_sample', default_args=default_args, schedule_interval=timedelta(minutes=10))


start = DummyOperator(task_id='run_this_first', dag=dag)

passing = KubernetesPodOperator(namespace='default',
image="Python:3.6",
cmds=["Python","-c"],
arguments=["print('hello world')"],
labels={"foo": "bar"},
name="passing-test",
task_id="passing-task",
get_logs=True,
dag=dag
)

failing = KubernetesPodOperator(namespace='default',
image="ubuntu:1604",
cmds=["Python","-c"],
arguments=["print('hello world')"],
labels={"foo": "bar"},
name="fail",
task_id="failing-task",
get_logs=True,
dag=dag
)

passing.set_upstream(start)
failing.set_upstream(start)

webserver_1 | Traceback (most recent call last): webserver_1 |
File "/usr/local/lib/python3.6/site-packages/airflow/models.py", line 377, in process_file webserver_1 | m = imp.load_source(mod_name, filepath) webserver_1 | File "/usr/local/lib/python3.6/imp.py", line 172, in load_source webserver_1 | module = _load(spec) webserver_1 | File "", line 684, in _load webserver_1 | File "", line 665, in _load_unlocked webserver_1 | File "", line 678, in exec_module webserver_1 | File "", line 219, in _call_with_frames_removed webserver_1 | File "/usr/local/airflow/dags/example_airflow.py", line 3, in webserver_1 | from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator webserver_1 | File "/usr/local/lib/python3.6/site-packages/airflow/contrib/operators/kubernetes_pod_operator.py", line 21, in webserver_1 | from airflow.contrib.kubernetes import kube_client, pod_generator, pod_launcher webserver_1 | File "/usr/local/lib/python3.6/site-packages/airflow/contrib/kubernetes/pod_launcher.py", line 25, in webserver_1 | from kubernetes import watch, client webserver_1 | ModuleNotFoundError: No module named 'kubernetes'

最佳答案

运行以下

pip install apache-airflow[kubernetes]

之后重新启动 Airflow 网络服务器和调度程序。

关于python - Airflow - ModuleNotFoundError : No module named 'kubernetes' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56296775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com