9

So I'm trying to run this script in Spyder (Python 3.9)

dset = xr.open_dataset(filename, decode_times=True, use_cftime=True)
print(dset)

But I keep on getting this error:

ValueError: found the following matches with the input file in xarray's IO backends: ['netcdf4', 'h5netcdf']. But their dependencies may not be installed, see:
https://docs.xarray.dev/en/stable/user-guide/io.html 
https://docs.xarray.dev/en/stable/getting-started-guide/installing.html

I have already installed via conda the ['netcdf4', 'h5netcdf'].

Did anyone run on the same issue? I have tried this also:

conda install -c anaconda netcdf4 h5netcdf scipy pydap zarr fsspec cftime rasterio cfgrib pooch

but the same valueerror arises.

kiwi_kimchi
  • 345
  • 3
  • 12
  • 1
    Are you able to import `netCDF4` or `h5netcdf`? There might be an issue with spyder picking up the wrong environment. – kmuehlbauer Apr 30 '22 at 14:04
  • Yes after several trials I ended up just making a new environment and just installing the packages I needed for the said new environment. Now everything works perfectly fine. – kiwi_kimchi May 09 '22 at 01:35

1 Answers1

4

Based on your error message, it looks like you are missing the netcdf4 and h5netcdf dependencies.

I would recommend installing using conda install in either your terminal/command line or your IDE if supported (e.g., Jupyter notebook cells): conda install netcdf4 h5netcdf

If you are using a Python environment other than your base environment, ensure you are installing to the environment are using for the project by navigating there in terminal (e.g., conda activate MYENV), or by switching to that environment kernel in your IDE.

You generally need to restart the kernel if you are using Jupyter for the change to take effect.