Whenever I try importing cfgrib it gives me runtime error that it could not load ecCodes library
import cfgrib
Here's the full error message
RuntimeError Traceback (most recent call last)
/tmp/ipykernel_6224/857012844.py in <module>
----> 1 import cfgrib
~/.local/lib/python3.8/site-packages/cfgrib/__init__.py in <module>
17
18 # cfgrib core API depends on the ECMWF ecCodes C-library only
---> 19 from .cfmessage import CfMessage
20 from .dataset import Dataset, DatasetBuildError, open_file, open_fileindex
21 from .messages import FileStream, Message
~/.local/lib/python3.8/site-packages/cfgrib/cfmessage.py in <module>
27 import numpy as np
28
---> 29 from . import abc, messages
30
31 LOG = logging.getLogger(__name__)
~/.local/lib/python3.8/site-packages/cfgrib/messages.py in <module>
26
27 import attr
---> 28 import eccodes # type: ignore
29 import numpy as np
30
~/.local/lib/python3.8/site-packages/eccodes/__init__.py in <module>
13 import sys
14
---> 15 from .eccodes import *
16 from .eccodes import __version__
17 from .eccodes import bindings_version
~/.local/lib/python3.8/site-packages/eccodes/eccodes.py in <module>
10 #
11 #
---> 12 from gribapi import __version__
13 from gribapi import bindings_version
14
~/.local/lib/python3.8/site-packages/gribapi/__init__.py in <module>
11 #
12
---> 13 from .gribapi import * # noqa
14 from .gribapi import __version__
15 from .gribapi import bindings_version
~/.local/lib/python3.8/site-packages/gribapi/gribapi.py in <module>
2226
2227
-> 2228 __version__ = grib_get_api_version()
2229
2230
~/.local/lib/python3.8/site-packages/gribapi/gribapi.py in grib_get_api_version()
2216
2217 if not lib:
-> 2218 raise RuntimeError("Could not load the ecCodes library!")
2219
2220 v = lib.grib_get_api_version()
RuntimeError: Could not load the ecCodes library!
I have installed cfgrib and ecCodes through pip
cfgrib 0.9.9.1
eccodes 1.4.0
eccodes-python 0.9.9
As stated on pypi (https://pypi.org/project/eccodes/) the eccodes python package relies on the eccodes system library. Based on the error message, you do not have it installed.
It is probably easiest to install it using conda:
conda install -c conda-forge eccodes