pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.63k stars 1.09k forks source link

Issue importing Xarray in Python 3.12.7 #9606

Closed gloriouslyawkwardlife closed 3 weeks ago

gloriouslyawkwardlife commented 1 month ago

What is your issue?

In [1]: import xarray
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[1], line 1
----> 1 import xarray

File /opt/homebrew/lib/python3.12/site-packages/xarray/__init__.py:3
      1 from importlib.metadata import version as _version
----> 3 from xarray import groupers, testing, tutorial
      4 from xarray.backends.api import (
      5     load_dataarray,
      6     load_dataset,
   (...)
     10     save_mfdataset,
     11 )
     12 from xarray.backends.zarr import open_zarr

File /opt/homebrew/lib/python3.12/site-packages/xarray/groupers.py:17
     14 import numpy as np
     15 import pandas as pd
---> 17 from xarray.coding.cftime_offsets import BaseCFTimeOffset, _new_to_legacy_freq
     18 from xarray.core import duck_array_ops
     19 from xarray.core.coordinates import Coordinates

File /opt/homebrew/lib/python3.12/site-packages/xarray/coding/cftime_offsets.py:56
     53 import pandas as pd
     54 from packaging.version import Version
---> 56 from xarray.coding.cftimeindex import CFTimeIndex, _parse_iso8601_with_reso
     57 from xarray.coding.times import (
     58     _is_standard_calendar,
     59     _should_cftime_be_used,
     60     convert_time_or_go_back,
     61     format_cftime_datetime,
     62 )
     63 from xarray.core.common import _contains_datetime_like_objects, is_np_datetime_like

File /opt/homebrew/lib/python3.12/site-packages/xarray/coding/cftimeindex.py:54
     51 import pandas as pd
     52 from packaging.version import Version
---> 54 from xarray.coding.times import (
     55     _STANDARD_CALENDARS,
     56     cftime_to_nptime,
     57     infer_calendar_name,
     58 )
     59 from xarray.core.common import _contains_cftime_datetimes
     60 from xarray.core.options import OPTIONS

File /opt/homebrew/lib/python3.12/site-packages/xarray/coding/times.py:14
     11 import pandas as pd
     12 from pandas.errors import OutOfBoundsDatetime, OutOfBoundsTimedelta
---> 14 from xarray.coding.variables import (
     15     SerializationWarning,
     16     VariableCoder,
     17     lazy_elemwise_func,
     18     pop_to,
     19     safe_setitem,
     20     unpack_for_decoding,
     21     unpack_for_encoding,
     22 )
     23 from xarray.core import indexing
     24 from xarray.core.common import contains_cftime_datetimes, is_np_datetime_like

File /opt/homebrew/lib/python3.12/site-packages/xarray/coding/variables.py:13
     10 import numpy as np
     11 import pandas as pd
---> 13 from xarray.core import dtypes, duck_array_ops, indexing
     14 from xarray.core.variable import Variable
     15 from xarray.namedarray.parallelcompat import get_chunked_array_type

File /opt/homebrew/lib/python3.12/site-packages/xarray/core/duck_array_ops.py:37
     34 from packaging.version import Version
     35 from pandas.api.types import is_extension_array_dtype
---> 37 from xarray.core import dask_array_ops, dtypes, nputils
     38 from xarray.core.options import OPTIONS
     39 from xarray.core.utils import is_duck_array, is_duck_dask_array, module_available

File /opt/homebrew/lib/python3.12/site-packages/xarray/core/dask_array_ops.py:3
      1 from __future__ import annotations
----> 3 from xarray.core import dtypes, nputils
      6 def dask_rolling_wrapper(moving_func, a, window, min_count=None, axis=-1):
      7     """Wrapper to apply bottleneck moving window funcs on dask arrays"""

File /opt/homebrew/lib/python3.12/site-packages/xarray/core/nputils.py:14
     11 from xarray.namedarray import pycompat
     13 # remove once numpy 2.0 is the oldest supported version
---> 14 if module_available("numpy", minversion="2.0.0.dev0"):
     15     from numpy.lib.array_utils import (  # type: ignore[import-not-found,unused-ignore]
     16         normalize_axis_index,
     17     )
     18 else:

File /opt/homebrew/lib/python3.12/site-packages/xarray/namedarray/utils.py:58, in module_available(module, minversion)
     55 if minversion is not None:
     56     version = importlib.metadata.version(module)
---> 58     return Version(version) >= Version(minversion)
     60 return True

File /opt/homebrew/lib/python3.12/site-packages/packaging/version.py:200, in Version.__init__(self, version)
    189 """Initialize a Version object.
    190 
    191 :param version:
   (...)
    196     exception will be raised.
    197 """
    199 # Validate the version and parse it into pieces
--> 200 match = self._regex.search(version)
    201 if not match:
    202     raise InvalidVersion(f"Invalid version: '{version}'")

TypeError: expected string or bytes-like object, got 'NoneType'
welcome[bot] commented 1 month ago

Thanks for opening your first issue here at xarray! Be sure to follow the issue template! If you have an idea for a solution, we would really welcome a Pull Request with proposed changes. See the Contributing Guide for more. It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better. Thank you!

keewis commented 1 month ago

you appear to have somehow broken numpy (or at least numpy.__version__: what the error is telling you is that numpy.__version__ is None evaluates to True). Can you check if numpy works as usual? (e.g. does np.mean(np.ones(100)) work?)