How do I resolve this AttributeError when using eccodes/grib?

2.2k views Asked by At

I'm working with cfgrib on macOS and I'm getting the following error when I try to use covert a grib file into xarray:

AttributeError: module 'pyeccodes.compat' has no attribute 'codes_grib_multi_support_off'

Here's the code I have so far:

import xarray as xr

import matplotlib.pyplot as plt
import matplotlib.style as sty
sty.use('classic')

import numpy as np

import cartopy.crs as ccrs
d7 = xr.open_dataset('2007_BLH.grib', engine='cfgrib')

I've downloaded everything that seems to be needed, including eccodes, pyeccodes, cfgrib. How can I resolve this issue?

2

There are 2 answers

0
HumphreysCarter On

Install the ecCodes binary with the package manager, see: https://github.com/ecmwf/cfgrib#binary-dependencies.

0
WxCZar On

I had the same error on a Windows 10 machine using Anaconda3, but hopefully my resolution will be helpful.

I think the issue was that I was installing metpy before cfgrib. It appears metpy set up some packages that conflicted with cfgrib because, after much trial and error, I created a fresh virtual python environment and resolved the issue doing the following:

conda install -n new_env cfgrib //install the package into my new virtual environment

Set up eccodes definitions path in environment variable...

Variable name: ECCODES_DEFINITION_PATH Variable Value: C:\Users\path\to\eccodes\definitions

I imagine this would look something like ECCODES_DEFINITION_PATH=./path/to/eccodes/definitions for your MacOS.