'Importing xarray raises not subscriptable issue

I have installed xarray and rioarray from my conda terminal but when I try to import them I get the following error. I am printing all the error text that I received. I see that there are other responses to this type of problems but they do not seem relevant to this import case - see for instance: TypeError: 'numpy._DTypeMeta' object is not subscriptable

import xarray as xr

 ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [43], in <cell line: 4>()
      2 import numpy as np
      3 import netCDF4 as nc
----> 4 import xarray as xr
      5 import rioxarray as rxr

File ~\Anaconda3\envs\geo\lib\site-packages\xarray\__init__.py:1, in <module>
----> 1 from . import testing, tutorial, ufuncs
      2 from .backends.api import (
      3     load_dataarray,
      4     load_dataset,
   (...)
      8     save_mfdataset,
      9 )
     10 from .backends.rasterio_ import open_rasterio

File ~\Anaconda3\envs\geo\lib\site-packages\xarray\testing.py:8, in <module>
      4 from typing import Hashable, Set, Union
      6 import numpy as np
----> 8 from xarray.core import duck_array_ops, formatting, utils
      9 from xarray.core.dataarray import DataArray
     10 from xarray.core.dataset import Dataset

File ~\Anaconda3\envs\geo\lib\site-packages\xarray\core\duck_array_ops.py:24, in <module>
     21 from numpy import take, tensordot, transpose, unravel_index  # noqa
     22 from numpy import where as _where
---> 24 from . import dask_array_compat, dask_array_ops, dtypes, npcompat, nputils
     25 from .nputils import nanfirst, nanlast
     26 from .pycompat import cupy_array_type, dask_array_type, is_duck_dask_array

File ~\Anaconda3\envs\geo\lib\site-packages\xarray\core\npcompat.py:38, in <module>
     36 # Type annotations stubs
     37 try:
---> 38     from numpy.typing import ArrayLike, DTypeLike
     39 except ImportError:
     40     # fall back for numpy < 1.20, ArrayLike adapted from numpy.typing._array_like
     41     from typing import Protocol

File ~\Anaconda3\envs\geo\lib\site-packages\numpy\typing\__init__.py:324, in <module>
    311 from ._scalars import (
    312     _CharLike_co,
    313     _BoolLike_co,
   (...)
    321     _VoidLike_co,
    322 )
    323 from ._shape import _Shape, _ShapeLike
--> 324 from ._dtype_like import (
    325     DTypeLike as DTypeLike,
    326     _SupportsDType,
    327     _VoidDTypeLike,
    328     _DTypeLikeBool,
    329     _DTypeLikeUInt,
    330     _DTypeLikeInt,
    331     _DTypeLikeFloat,
    332     _DTypeLikeComplex,
    333     _DTypeLikeTD64,
    334     _DTypeLikeDT64,
    335     _DTypeLikeObject,
    336     _DTypeLikeVoid,
    337     _DTypeLikeStr,
    338     _DTypeLikeBytes,
    339     _DTypeLikeComplex_co,
    340 )
    341 from ._array_like import (
    342     ArrayLike as ArrayLike,
    343     _ArrayLike,
   (...)
    358     _ArrayLikeBytes_co,
    359 )
    360 from ._generic_alias import (
    361     NDArray as NDArray,
    362     _DType,
    363     _GenericAlias,
    364 )

File ~\Anaconda3\envs\geo\lib\site-packages\numpy\typing\_dtype_like.py:16, in <module>
     13 import numpy as np
     15 from ._shape import _ShapeLike
---> 16 from ._generic_alias import _DType as DType
     18 from ._char_codes import (
     19     _BoolCodes,
     20     _UInt8Codes,
   (...)
     57     _ObjectCodes,
     58 )
     60 _DTypeLikeNested = Any  # TODO: wait for support for recursive types

File ~\Anaconda3\envs\geo\lib\site-packages\numpy\typing\_generic_alias.py:211, in <module>
    208 ScalarType = TypeVar("ScalarType", bound=np.generic, covariant=True)
    210 if TYPE_CHECKING or sys.version_info >= (3, 9):
--> 211     _DType = np.dtype[ScalarType]
    212     NDArray = np.ndarray[Any, np.dtype[ScalarType]]
    213 else:

TypeError: 'numpy._DTypeMeta' object is not subscriptable

what do you think could be the problem and how can I address it?

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source