1

Background

As recently as two months ago, I've had a working python script which i used regularly to combine netcdf4 weather files together.

However, ever since I recently updated my laptop, and reinstalled python (3.7 as per I.T. policy) and the latest python libraries, and the script has stopped working, it appears something has been deprecated, this has caused my code to stop working.

Problem

I am getting the error message: AttributeError: 'EntryPoints' object has no attribute 'get'

What I've tried

I've referred to these other posts on SO (link, link). From that I can see the issue has arisen from importlib-metadata (v5.0.0. +), Which comes as part of the standard python install (including 3.7) (I have importlib-metadata-6.6.0 on my machine)

I tried downgrading to an older version (importlib-metadata 4.0.0), but that resulted in a different problem.

I also asked I.T. to update my python to higher version (3.9, 3.10, etc). But apparently that's an entire process which could take ages to do.

Help Requested

Anyone know how I can resolve this issue.

Example Error message

Traceback (most recent call last):
  File "C:/Users/User/PycharmProjects/project/python_script.py", line 59, in get_era5
    merge_netcdf4 = xr.open_mfdataset(list, combine='by_coords')

  File "C:/Users/User/PycharmProjects/project\venv\lib\site-packages\xarray\backends\api.py", line 908, in open_mfdataset
    datasets = [open_(p, **open_kwargs) for p in paths]

  File "C:/Users/User/PycharmProjects/project\venv\lib\site-packages\xarray\backends\api.py", line 908, in <listcomp>
    datasets = [open_(p, **open_kwargs) for p in paths]

  File "C:/Users/User/PycharmProjects/project\venv\lib\site-packages\xarray\backends\api.py", line 479, in open_dataset
    engine = plugins.guess_engine(filename_or_obj)

  File "C:/Users/User/PycharmProjects/project\venv\lib\site-packages\xarray\backends\plugins.py", line 110, in guess_engine
    engines = list_engines()

  File "C:/Users/User/PycharmProjects/project\venv\lib\site-packages\xarray\backends\plugins.py", line 105, in list_engines
    entrypoints = entry_points().get("xarray.backends", ())

AttributeError: 'EntryPoints' object has no attribute 'get'

Example code

for single_date in daterange(start_date, end_date):
    YYYY = single_date.strftime("%Y")
    MM = single_date.strftime("%m")
    DD = single_date.strftime("%d")
    fname = fpath + YYYY + MM + DD + '_era5.nc'

    list.append(fname)

# Details
lat_toplot = np.arange(25.25, 25.50, 0.25) # last number is exclusive
lon_toplot = np.arange(140.25, 140.50, 0.25) # last number is exclusive

merge_netcdf4 = xr.open_mfdataset(list, combine='by_coords').sel(longitude=lon_toplot, latitude=lat_toplot)
Bobby Heyer
  • 531
  • 5
  • 18

1 Answers1

1

You might want to try to install a specific version of xarray that is compatible with your current version of importlib_metadata (6.6.0).

pip install xarray==0.17.0
Saxtheowl
  • 4,136
  • 5
  • 23
  • 32