Trying to import plotly.express, get "TypeError: Parameters to generic types must be types. Got NotImplemented."

I’m not sure what’s causing the issue, was working fine a couple weeks ago but all of a sudden I’m getting this error now. I’ve posted the whole error message below:

TypeError                                 Traceback (most recent call last)
<ipython-input-2-fe8f9c510f1a> in <module>
      3 import pandas as pd
      4 import plotly.graph_objects as go
----> 5 import plotly.express as px

/opt/conda/lib/python3.7/site-packages/plotly/express/__init__.py in <module>
     13     )
     14 
---> 15 from ._imshow import imshow
     16 from ._chart_types import (  # noqa: F401
     17     scatter,

/opt/conda/lib/python3.7/site-packages/plotly/express/_imshow.py in <module>
      9 
     10 try:
---> 11     import xarray
     12 
     13     xarray_imported = True

/opt/conda/lib/python3.7/site-packages/xarray/__init__.py in <module>
      1 import pkg_resources
      2 
----> 3 from . import testing, tutorial, ufuncs
      4 from .backends.api import (
      5     load_dataarray,

/opt/conda/lib/python3.7/site-packages/xarray/testing.py in <module>
      6 import numpy as np
      7 
----> 8 from xarray.core import duck_array_ops, formatting, utils
      9 from xarray.core.dataarray import DataArray
     10 from xarray.core.dataset import Dataset

/opt/conda/lib/python3.7/site-packages/xarray/core/duck_array_ops.py in <module>
     14 import pandas as pd
     15 
---> 16 from . import dask_array_compat, dask_array_ops, dtypes, npcompat, nputils
     17 from .nputils import nanfirst, nanlast
     18 from .pycompat import (

/opt/conda/lib/python3.7/site-packages/xarray/core/npcompat.py in <module>
     79 # Type annotations stubs
     80 try:
---> 81     from numpy.typing import ArrayLike, DTypeLike
     82 except ImportError:
     83     # fall back for numpy < 1.20, ArrayLike adapted from numpy.typing._array_like

/opt/conda/lib/python3.7/site-packages/numpy/typing/__init__.py in <module>
    313     _VoidLike_co,
    314 )
--> 315 from ._shape import _Shape, _ShapeLike
    316 from ._dtype_like import (
    317     DTypeLike as DTypeLike,

/opt/conda/lib/python3.7/site-packages/numpy/typing/_shape.py in <module>
     13 
     14 # Anything that can be coerced to a shape tuple
---> 15 _ShapeLike = Union[SupportsIndex, Sequence[SupportsIndex]]

/opt/conda/lib/python3.7/typing.py in inner(*args, **kwds)
    249         except TypeError:
    250             pass  # All real errors (not unhashable args) are raised below.
--> 251         return func(*args, **kwds)
    252     return inner
    253 

/opt/conda/lib/python3.7/typing.py in __getitem__(self, params)
    624             params = (params,)
    625         msg = "Parameters to generic types must be types."
--> 626         params = tuple(_type_check(p, msg) for p in params)
    627         _check_generic(self, params)
    628         return _subs_tvars(self, self.__parameters__, params)

/opt/conda/lib/python3.7/typing.py in <genexpr>(.0)
    624             params = (params,)
    625         msg = "Parameters to generic types must be types."
--> 626         params = tuple(_type_check(p, msg) for p in params)
    627         _check_generic(self, params)
    628         return _subs_tvars(self, self.__parameters__, params)

/opt/conda/lib/python3.7/typing.py in _type_check(arg, msg, is_argument)
    137         return arg
    138     if not callable(arg):
--> 139         raise TypeError(f"{msg} Got {arg!r:.100}.")
    140     return arg
    141 

TypeError: Parameters to generic types must be types. Got NotImplemented.

Hm odd. Looks like it might be an issue that originates from numpy… Have you searched for this same error message with numpy?

This was the closes one, but no answer as of yet.

The rest all relate to self made functions, not to importing libraries.

Searching for this error message across GitHub issues:

GitHub Issues: “TypeError: Parameters to generic types must be types. Got NotImplemented.” numpy

I see this issue with xarray in numpy’s repo: numpy 1.21 generates issue with importing xarray · Issue #19310 · numpy/numpy · GitHub from 16 days ago:

A fix for the issue is currently up at #19311 and should be in the next release.

In the meantime there two possible ways of remedying the situation:

Hope that helped!