在 Spyder 中打开 .GRIB 文件时出现 ECCODES 错误

ECCODES ERROR when opening .GRIB file in Spyder

我已经为我将要工作的环境访问了 Anaconda Prompt。

在那里,我将目录更改为我将要使用的 grib 文件所在的位置,为了安装 cfgrib,我使用了以下命令:

conda install -c conda-forge cfgrib

由于 Python 模块依赖于 ECMWF ecCodes 二进制库,在同一个 Anaconda Prompt 中,我 运行 以下命令:

conda install -c conda-forge eccodes

然后,在 Spyder 中打开文件,并尝试 运行 这个简单的脚本:

import xarray as xr

ds = xr.open_dataset('download.grib', engine='cfgrib')
ds

但出现以下错误:

Can't read index file 'C:\Users\name\Desktop\data\download.grib.90c91.idx' Traceback (most recent call last): File "C:\Users\name\anaconda3\envs\Weather\lib\site-packages\cfgrib\messages.py", line 351, in from_indexpath_or_filestream self = cls.from_indexpath(indexpath) File "C:\Users\name\anaconda3\envs\Weather\lib\site-packages\cfgrib\messages.py", line 323, in from_indexpath return pickle.load(file) EOFError: Ran out of input

然后,

An error ocurred while starting the kernel ECCODES ERROR : Unable to find boot.def. Context path=D:/bld/eccodes_1593015095851/_h_env/Library/share/eccodes/definitions

Possible causes: ‑ The software is not correctly installed ‑ The environment variable ECCODES_DEFINITION_PATH is defined but incorrect ecCodes assertion failed: `0' in D:\bld\eccodes_1593015095851\work\src\grib_context.c:226

我在这里错过了什么?


编辑 1

如果我使用Visual Studio代码也会出现这个问题。

在终端中,如果我在存储 GRIB 文件的目录中,并激活我正在使用的环境:

conda activate Weather

然后:

& C:/Users/name/anaconda3/envs/Weather/python.exe c:/Users/name/Desktop/data/3_climate/2mtemp_open.py

它给出了与上面相同的错误。

如错误所述,ECCODES_DEFINITION_PATH 未设置。

由于我在Windows10上使用Anaconda,路径如下

C:/Users/[USER]/Anaconda3/envs/envgeo/Library/share/eccodes/definitions

为了设置环境变量,可以简单地运行

setx ECCODES_DEFINITION_PATH "[ECCODES definition path/directory]"

这应该可以解决问题。

但是,可能会出现一个新的。由于 .grib 文件可能需要很多 运行,请考虑使用 NetCDF 格式的数据。