数值错误:在xarray的IO后端中,发现输入文件与以下匹配项:['netcdf4','h5netcdf']。

9

我试图在Spyder(Python 3.9)中运行这个脚本。

dset = xr.open_dataset(filename, decode_times=True, use_cftime=True)
print(dset)

但我一直收到这个错误:

ValueError: found the following matches with the input file in xarray's IO backends: ['netcdf4', 'h5netcdf']. But their dependencies may not be installed, see:
https://docs.xarray.dev/en/stable/user-guide/io.html 
https://docs.xarray.dev/en/stable/getting-started-guide/installing.html

我已经通过conda安装了['netcdf4', 'h5netcdf']。

有人遇到过同样的问题吗?我也尝试过这个方法:

conda install -c anaconda netcdf4 h5netcdf scipy pydap zarr fsspec cftime rasterio cfgrib pooch

但是同样的ValueError错误会出现。


1
你能导入 netCDF4h5netcdf 吗?可能是 Spyder 拾取了错误的环境。 - kmuehlbauer
经过几次尝试后,我最终决定创建一个新的环境,并仅安装所需的软件包。现在一切都运行得非常完美。 - kiwi_kimchi
1个回答

4
根据您的错误信息,看起来您缺少netcdf4和h5netcdf的依赖项。
我建议您在终端/命令行或者支持的IDE(例如Jupyter笔记本单元格)中使用conda install进行安装:conda install netcdf4 h5netcdf 如果您正在使用除基本环境之外的Python环境,请确保您正在安装到项目所使用的环境中,可以通过在终端中导航到该环境(例如conda activate MYENV),或者在IDE中切换到该环境的内核来实现。
如果您正在使用Jupyter进行更改,通常需要重新启动内核才能生效。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接