ecmwf / cfgrib

A Python interface to map GRIB files to the NetCDF Common Data Model following the CF Convention using ecCodes
Apache License 2.0
400 stars 77 forks source link

`AttributeError: module 'eccodes' has no attribute 'codes_grib_multi_support_reset_file'` after the 0.9.9.0 release #227

Closed nlhll closed 3 years ago

nlhll commented 3 years ago

Hi there,

Worked fine on 0.9.8.5 version, however started throwing an AttributeError on the 0.9.9.0 one. As an example: cfgrib.open_dataset(file_path, backend_kwargs={"filter_by_keys": {"numberOfPoints": 2556, "typeOfLevel": "hybrid", "edition": 2, "level": 128}})

Can't create file 'INDEX_FILE.idx'
Traceback (most recent call last):
  File "../python/lib/python3.7/site-packages/cfgrib/messages.py", line 344, in from_indexpath_or_filestream
    self = cls.from_filestream(filestream, index_keys)
  File "../python/lib/python3.7/site-packages/cfgrib/messages.py", line 293, in from_filestream
    for message in filestream:
  File "../python/lib/python3.7/site-packages/cfgrib/messages.py", line 229, in __iter__
    with multi_enabled(file):
  File "../python/lib/python3.7/contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "../python/lib/python3.7/site-packages/cfgrib/messages.py", line 51, in multi_enabled
    eccodes.codes_grib_multi_support_reset_file(file)
AttributeError: module 'eccodes' has no attribute 'codes_grib_multi_support_reset_file'
Can't read index file 'INDEX_FILE.idx'
Traceback (most recent call last):
  File "../python/lib/python3.7/site-packages/cfgrib/messages.py", line 353, in from_indexpath_or_filestream
    index_mtime = os.path.getmtime(indexpath)
  File "../python/lib/python3.7/genericpath.py", line 55, in getmtime
    return os.stat(filename).st_mtime
FileNotFoundError: [Errno 2] No such file or directory: 'INDEX_FILE.idx'

Any idea on what might be the cause of that?

alexamici commented 3 years ago

The latest version of cfgrib is compatible only with fairly new version of the eccodes python package, but I failed to add this minimum version in the setup.py. I'll add it and make a new release.

As a work-around you need to update the package with ecCodes python bindings depending on you install setup. This is different for pip, conda and other installation strategies.

Thanks for the report.

xigrug commented 3 years ago

I also have this question : ds = xr.open_dataset("C:\\Users\\liuc\\Downloads\\era5-levels-members.grib", engine="cfgrib")

W:\software\anaconda\lib\site-packages\cfgrib\messages.py in multi_enabled(file) 49 # @alexamici: I'm note sure this is thread-safe. See :#141 50 # ---> 51 eccodes.codes_grib_multi_support_reset_file(file) 52 try: 53 yield

AttributeError: module 'eccodes' has no attribute 'codes_grib_multi_support_reset_file'

Name Version Build Channel

eccodes 2.14.1 hbda0969_1 conda-forge python-eccodes 0.9.3 py38hc8d92b1_1 conda-forge xarray 0.18.0 pyhd3eb1b0_1