You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kubernetes Python客户端26.1.0版本无法导入V1Event的问题求助

Kubernetes Python客户端26.1.0版本无法导入V1Event的问题求助

大家好,我最近碰到了一个棘手的问题:升级到Kubernetes Python客户端26.1.0版本后,项目里原本正常使用的V1Event突然没法导入了。

之前我是这么导入相关Kubernetes类的:

from kubernetes.client import (
    V1ContainerState,
    V1ContainerStateRunning,
    V1ContainerStateTerminated,
    V1ContainerStateWaiting,
    V1ContainerStatus,
    V1Event,
)

现在运行测试直接抛出了导入错误,完整的错误日志如下:

home/dev/ .tox/run-tests/lib/python3.8/site-packages/_pytest/config/__init__.py:325: PluggyTeardownRaisedWarning: A plugin raised an exception during an old-style hookwrapper teardown.

Plugin: helpconfig, Hook: pytest_cmdline_parse

ConftestImportFailure: ImportError: cannot import name 'V1Event' from 'kubernetes' (/home/dev/ .tox/run-tests/lib/python3.8/site-packages/kubernetes/__init__.py) (from /home/dev/ tests/conftest.py)

For more information see the pluggy documentation

  config = pluginmanager.hook.pytest_cmdline_parse(

ImportError while loading conftest '/home/dev/ tests/conftest.py'.

tests/conftest.py:19: in <module>

    from .mockubernetes_utils import Mocks

tests/mockubernetes_utils.py:19: in <module>

    from kubernetes import  V1Event

E   ImportError: cannot import name 'V1Event' from 'kubernetes' (/home/dev/ .tox/run-tests/lib/python3.8/site-packages/kubernetes/__init__.py)

run-tests: exit 4 (3.43 seconds) /home/dev > pytest --ignore target/ --cov --cov-report=html --cov-report=xml pid=24115

我自己也尝试换了导入路径,比如从kubernetes.client.models导入相关内容,但同样失败了,测试代码是这样的:

import kubernetes.client.models

对应的错误日志如下:

ConftestImportFailure: ModuleNotFoundError: No module named 'kubernetes.client.model' (from /home/dev/ tests/conftest.py)

For more information see the pluggy documentation

  config = pluginmanager.hook.pytest_cmdline_parse(

ImportError while loading conftest '/home/dev/ tests/conftest.py'.

tests/conftest.py:19: in <module>

    from .mockubernetes_utils import Mocks

tests/mockubernetes_utils.py:18: in <module>

    from kubernetes.client.model import V1Event

E   ModuleNotFoundError: No module named 'kubernetes.client.model'

有没有大佬知道这个问题该怎么解决?V1Event在新版本里是被迁移到其他路径了,还是有什么替代的方案呀?

备注:内容来源于stack exchange,提问作者CuriestCoder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 11:58:15