4

我正在尝试使用ECMWF GRIB_API从 Python 访问 GRIB 文件。我收到这个错误

Traceback (most recent call last):
  File "/home/martin/markj/JustImportGRIB.py", line 1, in <module>
    from gribapi import *
ImportError: No module named gribapi

一行代码:)

from gribapi import *

我正在使用 Anaconda Python 2.7.12,Linux Centos 64 位,以用户身份安装,如果相关的话,没有将 Anaconda 添加到路径中 - 系统 Python (2.6) 在路径上。我从 Google 最热门的Pingu Carsti 频道安装了 GRIB_API 。conda 安装没有报告任何错误。

[martin@bonnie ~]$ anaconda2/bin/conda install -c pingucarsti grib_api=1.10.4
Fetching package metadata .........
Solving package specifications: ..........

Package plan for installation in environment /home/martin/anaconda2:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    grib_api-1.10.4            |                3         1.7 MB  pingucarsti

The following NEW packages will be INSTALLED:

    grib_api: 1.10.4-3 pingucarsti

Proceed ([y]/n)? y

Fetching packages ...
grib_api-1.10. 100% |################################| Time: 0:00:01   1.24 MB/s
Extracting packages ...
[      COMPLETE      ]|###################################################| 100%
Linking packages ...
[      COMPLETE      ]|###################################################| 100%

我发现一些关于此错误的错误报告是由 ECMWF GRIB_API 中的错误引起的,但我对 Anaconda(或者可能是 Python)知之甚少,无法弄清楚如何应用这些变通方法

4

2 回答 2

3

我用pygrib读取 Python 中的 GRIB 文件。我已经成功地将它安装在 conda 虚拟环境中(Ubuntu 16.04 上的 Miniconda2)。这对我有用:

  1. 为 pygrib 安装系统依赖项:

    sudo apt-get install libjpeg9

    sudo apt-get install libgrib-api-dev

  2. 从 conda-forge 频道安装 pygrib 和 ecmwf_grib。

    conda install -c conda-forge pygrib ecmwf_grib

于 2017-01-06T15:46:42.943 回答
1

python-eccodes尝试 conda-forge 的构建(注意:这不是 C 库的eccodes)。

它是如何构建的:https ://github.com/conda-forge/python-eccodes-feedstock/blob/master/recipe/meta.yaml

ECMWF 的 ecCodes 库是其 GRIB API 的下一个版本,与旧的 GRIB API 极为相似。

pelson> conda create -n gribby -c conda-forge python-eccodes
Fetching package metadata .............
Solving package specifications: .

Package plan for installation in environment /Users/pelson/miniconda/envs/gribby:

The following NEW packages will be INSTALLED:

    ca-certificates: 2017.7.27.1-0         conda-forge
    curl:            7.54.1-0              conda-forge
    eccodes:         2.4.0-0               conda-forge
    hdf4:            4.2.12-0              conda-forge
    hdf5:            1.8.18-1              conda-forge
    intel-openmp:    2018.0.0-h68bdfb3_7   defaults   
    jasper:          1.900.1-4             conda-forge
    jpeg:            9b-1                  conda-forge
    krb5:            1.14.2-0              conda-forge
    libgfortran:     3.0.1-h93005f0_2      defaults   
    libnetcdf:       4.4.1.1-8             conda-forge
    libpng:          1.6.28-1              conda-forge
    libssh2:         1.8.0-1               conda-forge
    mkl:             2018.0.0-h5ef208c_6   defaults   
    ncurses:         5.9-10                conda-forge
    numpy:           1.13.3-py27h62f9060_0 defaults   
    openssl:         1.0.2l-0              conda-forge
    python:          2.7.14-0              conda-forge
    python-eccodes:  2.4.0-py27_1          conda-forge
    readline:        6.2-0                 conda-forge
    sqlite:          3.13.0-1              conda-forge
    tk:              8.5.19-2              conda-forge
    zlib:            1.2.8-3               conda-forge
#
# To activate this environment, use:
# > source activate gribby
#
# To deactivate an active environment, use:
# > source deactivate
#


pelson> source activate gribby
python(gribby) pelson> python
Python 2.7.14 | packaged by conda-forge | (default, Oct  5 2017, 23:08:53) 
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gribapi
>>> gribapi.__version__
'2.4.0'
于 2017-11-04T08:28:36.073 回答