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

conda为Python3.7环境安装不兼容prometheus_client的问题排查

Python3.7环境中JupyterLab导入失败的依赖兼容问题

环境配置与操作步骤

  • 系统:Ubuntu 20.04,使用标准Miniconda3
  • 环境配置文件test_env.yaml内容:
name: test-env
channels:
    - conda-forge
    - nodefaults
dependencies:
    - python=3.7
    - ipykernel
    - jupyterlab
  • 执行命令创建并激活环境:conda env create -f test_env.yaml

报错详情

激活环境后进入Python会话,导入jupyterlab时触发以下错误:

(test-env) [~]$ python
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:21) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import jupyterlab
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/olamarre/miniconda3/envs/test-env/lib/python3.7/site-packages/jupyterlab/__init__.py", line 7, in <module>
    from .handlers.announcements import (  # noqa
  File "/home/olamarre/miniconda3/envs/test-env/lib/python3.7/site-packages/jupyterlab/handlers/announcements.py", line 14, in <module>
    from jupyter_server.base.handlers import APIHandler
  File "/home/olamarre/miniconda3/envs/test-env/lib/python3.7/site-packages/jupyter_server/base/handlers.py", line 18, in <module>
    import prometheus_client
  File "/home/olamarre/miniconda3/envs/test-env/lib/python3.7/site-packages/prometheus_client/__init__.py", line 3, in <module>
    from . import (
  File "/home/olamarre/miniconda3/envs/test-env/lib/python3.7/site-packages/prometheus_client/metrics.py", line 5, in <module>
    from typing import (
ImportError: cannot import name 'Literal' from 'typing' (/home/olamarre/miniconda3/envs/test-env/lib/python3.7/typing.py)
>>> 

经排查,自动安装的prometheus_client版本为0.18,该版本依赖Python3.8及以上版本才支持的typing.Literal,与当前Python3.7环境不兼容。手动指定安装prometheus_client=0.17可解决该问题。

疑问

  • 这是否是JupyterLab的conda依赖树配置问题?若是,如何上报修复?
  • 或是本地环境问题?若是,该如何调试?
    另外怀疑近期创建的Python3.11环境中缓存的prometheus_client被复用至Python3.7环境。

内容的提问来源于stack exchange,提问作者olamarre

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 06:46:30