气流-ModuleNotFoundError:没有名为'kubernetes'的模块

时间:2019-05-24 16:57:29

标签: python kubernetes pip airflow

我在计算机上安装了Python和Docker,并试图导入 from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator,但是当我连接泊坞窗时,收到消息,提示该模块不存在。我已经做过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 |追溯(最近一次通话):webserver_1 |
  文件“ /usr/local/lib/python3.6/site-packages/airflow/models.py”,行   377,在process_file webserver_1中| m = imp.load_source(mod_name,   文件路径)webserver_1 |文件“ /usr/local/lib/python3.6/imp.py”,   load_source webserver_1中的第172行|模块= _load(规格)   webserver_1 |文件“”,行684,在   _load webserver_1 | _load_unlocked Webserver_1中的文件“”,第665行| exec_module webserver_1中的文件“”,行678   |在第219行的文件“”中   _call_with_frames_removed网络服务器_1 |在第3行的文件“ /usr/local/airflow/dags/example_airflow.py”   webserver_1 |从   airflow.contrib.operators.kubernetes_pod_operator导入   KubernetesPodOperator webserver_1 |文件   “ /usr/local/lib/python3.6/site-packages/airflow/contrib/operators/kubernetes_pod_operator.py”,   webserver_1中的第21行|从   airflow.contrib.kubernetes导入kube_client,pod_generator,   pod_launcher webserver_1 |文件   “ /usr/local/lib/python3.6/site-packages/airflow/contrib/kubernetes/pod_launcher.py”,   webserver_1中的第25行|来自kubernetes import watch,   客户端webserver_1 | ModuleNotFoundError:未命名模块   'kubernetes'

3 个答案:

答案 0 :(得分:1)

尝试任何这些导入。其中一个已被弃用,因此您的版本可能不再受支持。

    #from airflow.providers.cncf.kubernetes.operators.kubernetes_pod import KubernetesPodOperator
    from airflow.contrib.operators.kubernetes_pod_operator import KubernetesPodOperator

答案 1 :(得分:0)

它尝试导入名为kubernetes的模块。尝试:

@Override
public void onCreate(Bundle savedInstanceState)
{
    // I assume you accidentally left out these lines
    super.onCreate(savedInstanceState);
    setContentView(R.id.your_content_view);

    if (savedInstanceState == null) {
        FragmentA fragA = new FragmentA();
        FragmentTransaction fragmentTransaction = 
        getSupportFragmentManager().beginTransaction();
        fragmentTransation.replace(R.id.basic_frame, fragA);
        fragmentTransaction.commit();
    }
}

答案 2 :(得分:0)

运行以下

pip install apache-airflow[kubernetes]

然后重新启动Airflow Web服务器和调度程序。