2016-09-30 262 views
3

我想用ECMWF GRIB_API從Python訪問GRIB文件。我得到這個錯誤的代碼:)使用Python Anaconda包時導入錯誤grib_api

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 *

我使用Python的蟒蛇2.7.12,Linux的Centos的64位,安裝爲用戶和未添加蟒蛇到如果這是相關的路徑 - 系統Python(2.6)在路徑上。我從Pingu Carsti channel安裝了GRIB_API,這是Google的熱門遊戲。 conda安裝沒有報告任何錯誤。

[[email protected] ~]$ 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的錯誤而引起這個錯誤,但我不知道有足夠的瞭解蟒蛇(或者Python)的弄清楚如何應用workarounds

+0

PinguCarsti建議我使用[康達鍛](https://anaconda.org/conda-forge/ecmwf_grib)信道代替。我仍然遇到麻煩。我也試過[SciTools](https://anaconda.org/scitools/ecmwf_grib),但仍然遇到麻煩。 – MarkJ

+0

這不是你的問題的答案,但它可能會有所幫助... https://stackoverflow.com/a/44246941/175793 – errata

回答

1

我用Python讀取GRI文件pygrib。我已經成功地將它安裝在conda虛擬環境中(Ubuntu 16.04上的Miniconda2)。這裏是爲我工作:

  1. 爲pygrib安裝系統的依賴:

    sudo apt-get install libjpeg9

    sudo apt-get install libgrib-api-dev

  2. 從康達鍛通道安裝pygrib和ecmwf_grib。

    conda install -c conda-forge pygrib ecmwf_grib

+0

感謝您的答案,如果我有時間,我會自己嘗試。目前正在進行其他項目...... – MarkJ

0

嘗試暢達,僞造的建立在中的python-eccodes(注:這不是eccodes這是C庫)。

它是如何構建的: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'