我在 Ubuntu 20.04 上通过标准 miniconda3 安装运行 conda。我需要 Python 3.7 环境并有以下简化的 conda 环境文件 (
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)
>>>
jupyterlab 依赖项之一,
prometheus_client
,尝试进行仅适用于 Python 3.8 及更高版本的导入,不适用于 Python 3.7。因此,该 prometheus_client
软件包版本(0.18)与我的环境不兼容。如果我明确告诉 conda 安装同一包的早期版本(通过将 prometheus_client=0.17
添加到环境文件中的依赖项),问题就得到解决。
我的问题是:这可能是
jupyterlab
的依赖树的conda配置问题吗? (如果是这样,我如何标记这个问题以解决它?)或者这可能是我的问题吗? (如果是这样,我应该如何调试它?)
让我怀疑的是,我最近创建了一个单独的Python 3.11环境,也安装了
jupyterlab
(同样的方式,但在conda环境文件中使用python=3.11
),所以我想知道缓存的prometheus_client
包是否适用于该环境环境正在被 Python 3.7 环境重用。