带有 numpy 2.0 的基本 python 抛出一个大错误。我认为 metpy 1.6 解决了 numpy 2.0 的问题。还有人有这个吗? 谢谢。
操作系统:Ubuntu 24.04
代码:
#!/home/ccc/miniconda3/bin/python
import numpy as np
from metpy.units import units
distance = np.arange(1, 5) * units.meters
执行(错误代码):
Traceback (most recent call last):
File "/home/ccc/t1.py", line 3, in <module>
from metpy.units import units
File "/home/ccc/miniconda3/lib/python3.12/site-packages/metpy/__init__.py", line 13, in <module>
from .xarray import * # noqa: F401, F403, E402
^^^^^^^^^^^^^^^^^^^^^
File "/home/ccc/miniconda3/lib/python3.12/site-packages/metpy/xarray.py", line 27, in <module>
import xarray as xr
File "/home/ccc/miniconda3/lib/python3.12/site-packages/xarray/__init__.py", line 1, in <module>
from xarray import testing, tutorial
File "/home/ccc/miniconda3/lib/python3.12/site-packages/xarray/testing.py", line 10, in <module>
from xarray.core import duck_array_ops, formatting, utils
File "/home/ccc/miniconda3/lib/python3.12/site-packages/xarray/core/duck_array_ops.py", line 36, in <module>
from xarray.core import dask_array_ops, dtypes, nputils
File "/home/ccc/miniconda3/lib/python3.12/site-packages/xarray/core/dask_array_ops.py", line 3, in <module>
from xarray.core import dtypes, nputils
File "/home/ccc/miniconda3/lib/python3.12/site-packages/xarray/core/dtypes.py", line 43, in <module>
(np.bytes_, np.unicode_), # numpy promotes to unicode
^^^^^^^^^^^
File "/home/ccc/miniconda3/lib/python3.12/site-packages/numpy/__init__.py", line 400, in __getattr__
raise AttributeError(
AttributeError: `np.unicode_` was removed in the NumPy 2.0 release. Use `np.str_` instead.
如果仔细查看回溯,您会发现此错误来自 xarray 代码,而不是 metpy。看起来这个问题与 this issues 相同,并由 this Pull Request 修复。通过确保安装了
xarray >= 2023.09.0
,您应该能够在您的环境中修复此问题。