cfgrib icon indicating copy to clipboard operation
cfgrib copied to clipboard

Using cfgrib with xarray.open_dataset fails due to "'EntryPoint' object has no attribute 'module_name'" AttributeError

Open joshdorrington opened this issue 3 years ago • 2 comments

Versions and dependencies

I have installed cfgrib using mamba. I have checked that cfgrib is installed correctly:

>>python -m cfgrib selfcheck
Found: ecCodes v2.26.0.
Your system is ready.

and I have retrieved the test grib file using wget.

>>import xarray as xr
>>import sys

>>print(sys.version)
3.9.10 | packaged by conda-forge | (main, Feb  1 2022, 21:24:11) 
[GCC 9.4.0]

>>print(xr.__version__)
0.20.1

Nature of Error When I run: xr.open_dataset('era5-levels-members.grib',engine='cfgrib')

I receive an error (posted in full at the bottom) which seems to derive from this object: EntryPoint(name='cfgrib', value='cfgrib.xarray_plugin:CfGribBackend', group='xarray.backends') having no attribute 'module_name', which occurs at the bottom of the following stacktrace:

xr.open_dataset->plugins.get_backend(engine)->list_engines()->build_engines(entrypoints)->remove_duplicates(entrypoints)

I would appreciate any assistance in getting this working!

Full error message:

AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_23372/811187540.py in <module>
      4 
      5 get_ipython().run_line_magic('debug', '')
----> 6 xr.open_dataset('era5-levels-members.grib',engine='cfgrib')

~/miniconda3/lib/python3.9/site-packages/xarray/backends/api.py in open_dataset(filename_or_obj, engine, chunks, cache, decode_cf, mask_and_scale, decode_times, decode_timedelta, use_cftime, concat_characters, decode_coords, drop_variables, backend_kwargs, *args, **kwargs)
    479         engine = plugins.guess_engine(filename_or_obj)
    480 
--> 481     backend = plugins.get_backend(engine)
    482 
    483     decoders = _resolve_decoders_kwargs(

~/miniconda3/lib/python3.9/site-packages/xarray/backends/plugins.py in get_backend(engine)
    156     """Select open_dataset method based on current engine."""
    157     if isinstance(engine, str):
--> 158         engines = list_engines()
    159         if engine not in engines:
    160             raise ValueError(

~/miniconda3/lib/python3.9/site-packages/xarray/backends/plugins.py in list_engines()
    101 def list_engines():
    102     entrypoints = entry_points().get("xarray.backends", ())
--> 103     return build_engines(entrypoints)
    104 
    105 

~/miniconda3/lib/python3.9/site-packages/xarray/backends/plugins.py in build_engines(entrypoints)
     90         if backend.available:
     91             backend_entrypoints[backend_name] = backend
---> 92     entrypoints = remove_duplicates(entrypoints)
     93     external_backend_entrypoints = backends_dict_from_pkg(entrypoints)
     94     backend_entrypoints.update(external_backend_entrypoints)

~/miniconda3/lib/python3.9/site-packages/xarray/backends/plugins.py in remove_duplicates(entrypoints)
     27         matches_len = len(matches)
     28         if matches_len > 1:
---> 29             selected_module_name = matches[0].module_name
     30             all_module_names = [e.module_name for e in matches]
     31             warnings.warn(

AttributeError: 'EntryPoint' object has no attribute 'module_name'

joshdorrington avatar Sep 23 '22 11:09 joshdorrington

Hi @joshdorrington,

I've just installed cfgrib into a mamba environment and it worked ok for me. I think it's worth double-checking that everything is installed where you think it is, e.g. that cfgrib is installed into the same environment that xarray is installed into.

Best regards, Iain

iainrussell avatar Oct 04 '22 12:10 iainrussell

This has been fixed 1 year ago in xarray: https://github.com/pydata/xarray/pull/5959 Consider updating xarray.

headtr1ck avatar Oct 24 '22 19:10 headtr1ck