无法导入 cfgrib

Unable to import cfgrib

每当我尝试导入 cfgrib 时,都会出现无法加载 ecCodes 库的运行时错误

import cfgrib

这是完整的错误信息

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!

我已经通过 pip 安装了 cfgrib 和 ecCodes

cfgrib                 0.9.9.1             
eccodes                1.4.0               
eccodes-python         0.9.9

如 pypi (https://pypi.org/project/eccodes/) 所述,eccodes python 包依赖于 eccodes 系统库。根据错误信息,您没有安装它。

使用 conda 安装它可能是最简单的:

conda install -c conda-forge eccodes