Why does conda install non-compatible jupyterlab dependency (prometheus_client) in my environment?

95 views Asked by At

I am running conda via a standard miniconda3 installation on Ubuntu 20.04. I need a Python 3.7 environment and have the following simplified conda environment file (test_env.yaml):

name: test-env
channels:
    - conda-forge
    - nodefaults
dependencies:
    - python=3.7
    - ipykernel
    - jupyterlab

After creating the environment using conda env create -f test_env.yaml and activating it, I try to import jupyterlab in a Python session but get an import error:

(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)
>>> 

One of the jupyterlab dependencies, prometheus_client, tries to make an import that only works in Python 3.8 and above, not Python 3.7. That prometheus_client package version (0.18) is thus incompatible with my environment. If I explicitly tell conda to install an earlier version of the same package (by adding prometheus_client=0.17 to the dependencies in the environment file), the problem is fixed.

My question is: Could this be an issue with the conda configuration of the dependency tree of jupyterlab? (and if so, how can I flag this issue to get it fixed?) Or could this be an issue on my end? (and if so, how should I debug it?)

What makes me suspiscious is that I recently created a separate Python 3.11 environment that also installed jupyterlab (same way, but with python=3.11 in the conda environment file), so I am wondering if the cached prometheus_client package for that environment is being reused for the Python 3.7 environment.

1

There are 1 answers

2
olamarre On

Potential answer to my own question - I just noticed in the prometheus conda package files that the upgrade to 0.18 was made a few days ago, and the requirements only impose a python >= 3.6. I suspect this might be the issue, will follow up with the developers (opened a github issue).

enter image description here