【问题标题】:ImportError when using Python Anaconda package grib_api使用 Python Anaconda 包 grib_api 时的 ImportError
【发布时间】:2017-11-04 16:28:36
【问题描述】:

我正在尝试使用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) 位于路径中。我从Pingu Carsti channel 安装了 GRIB_API,这是 Google 的热门搜索。 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%

我发现some bug reports 关于这个错误是由 ECMWF GRIB_API 中的错误引起的,但我对 Anaconda(或者可能是 Python)的了解还不够,无法弄清楚如何应用 workarounds

【问题讨论】:

标签: python anaconda grib-api


【解决方案1】:

我使用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

【讨论】:

  • 感谢您的回答,如果我有时间我会自己尝试一下。目前正在从事其他项目......
【解决方案2】:

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'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 1970-01-01
    • 2015-10-22
    • 2016-04-06
    相关资源
    最近更新 更多