pythonanacondaspydergribeccodes

ECCODES ERROR when opening .GRIB file in Spyder


I have accessed Anaconda Prompt for the environment that I will be working.

Once there, I have changed the directory to the place where I have the grib files that I will be working with, in order to install cfgrib, I have used the following command:

conda install -c conda-forge cfgrib

As the Python module depends on ECMWF ecCodes binary library, in the same Anaconda Prompt, I ran the following command:

conda install -c conda-forge eccodes

Then, opened the file in Spyder, and tried to run this simple script:

import xarray as xr

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

But got the following error:

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

Then,

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

Error starting the kernel

What am I missing here?


Edit 1

The problem also happens if I use Visual Studio Code.

In the terminal, if I am inside the directory that the GRIB files are stored, and I activate the environment that I am working with:

conda activate Weather

And then:

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

It gives the same error as above.


Solution

  • As the error says, ECCODES_DEFINITION_PATH was not set.

    As I am using Anaconda on Windows 10, the path is the following

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

    In order to set the environment variable, one can simply run

    setx ECCODES_DEFINITION_PATH "[ECCODES definition path/directory]"
    

    This should solve the problem.

    However, a new one may emerge. As the .grib file may take a lot to run, consider using the data in the format NetCDF.