Skip to content

Instantly share code, notes, and snippets.

@emmanuelnk
Last active February 3, 2022 19:56
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmanuelnk/406eee50c388f4f73dcdff521f2aa7b2 to your computer and use it in GitHub Desktop.
Save emmanuelnk/406eee50c388f4f73dcdff521f2aa7b2 to your computer and use it in GitHub Desktop.
How to install PyGrib with ECCodes (Python 3.6.5, Ubuntu 18, 16, RHEL)

How to install PyGrib with ECCodes (Python 3.6.5, Ubuntu 19, 18, 16, RHEL, Lambda, Linux AMI, Docker)

[ last_updated: 07-JAN-2020 ]

Recently I've had to work with Meterological data of the GRIB format. Needless to say, if you're reading this, you probably know how hard it is to get a library that can read them and even harder, setting up those libraries. Pygrib for python is by far the best library for reading grib files but the installation can leave you dizzy

In this tutorial I use Ubuntu 18 and python 3.6.5 virtualenv. Note: You don't have to use virtualenv Python. You can just as well use your system Python 3 however I personally find virtualenv a clean way to deal with these kind of complicated setups (prevents me mucking up my system's Python). This setup should also work with lower and higher Ubuntu versions (as someone below mentioned) and other Linux distros (like RHEL - AWS Linux AMI etc). The key to this installation is to build eccodes correctly (for your machine architecture) and successfully point pygrib to it. Let me know below if it worked for you with other distros!

But before you go any further, the alternative way to install Pygrib is to use the Conda version (this is by far the easiest way since all the binaries are pre-built): https://anaconda.org/conda-forge/pygrib But it comes with the disadvantage that it is quite large. This is fine but here is the dealbreaker: Since I will be uploading this to AWS lambda, I also need to be able to build Pygrib on either an AWS lambda EC2 (Linux AMI) or AWS Lambda docker image that replicates the AWS Lambda machine architecture. This ensures that the built binaries will work on lambda. Those built for Conda do not work on AWS machine architecture like lambda. I will put the AWS lambda deploy in a separate gist.

UPDATE: User @preeth1 added a very useful dockerfile for this setup down below in the comments. So if you're really just in a rush, that's another option. If you want to understand the finer details behind the setup, read on.

So without further ado, let's begin!

Python Virtualenv and CMake setup

Ubuntu 18 ships with both Python 2 and 3 but if yours doesn't install Python 3.6.5 by updating aptitude:

sudo apt-get update
sudo apt-get -y upgrade

check the version of python3 installed:

python3 -V

install Python's package manager, pip:

sudo apt-get install -y python3-pip

install Python development tools if you don't have them

sudo apt-get install python3-dev

install python virtualenv

sudo pip3 install virtualenv 

Navigate to the directory where you want to create your env and create it, then activate it: virtualenv <NAME OF YOUR VIRTUAL ENV> .In my case, 'venv':

virtualenv venv 
source venv/bin/activate

you should see something like: (venv) user@computer: you can deactivate it with $ deactivate anytime to use your system's python

Your virtual Python is now ready. Do you have CMAKE and MAKE though? You'll need them to build eccodes

sudo apt-get install build-essential
sudo apt-get install cmake

Eccodes setup

First part is done, now time to build eccodes. For more details, see: https://confluence.ecmwf.int/display/ECC/ecCodes+installation

Create a directory where you will build eccodes. I usually put custom builds in one folder called custom_builds in my HOME dir. You can use whatever

mkdir ~/custom_builds/eccodes
cd ~/custom_builds/eccodes

here we will download the eccodes tar file first. Get the link for the latest release here: https://confluence.ecmwf.int//display/ECC/Releases In my case the latest is 2.8.2:

wget https://confluence.ecmwf.int/download/attachments/45757960/eccodes-2.8.2-Source.tar.gz?api=v2

uncompress it:

tar -xzf  eccodes-2.8.2-Source.tar.gz?api=v2

create your build directory and cd into it:

mkdir build ; cd build

Now here take a moment to understand the cmake build requirements for eccodes.

From the installation link above, you'll see there are various params that you can enable or disable for any feature you need enabled, like png, jpg, fortran etc. Ensure you have the required dependency installed on your system. In my case, I didn't need any of the extra options. I just needed to read grib files. Take a look at this link: https://jswhit.github.io/pygrib/docs/index.html if you need more information about those extra dependencies. For example you would need libpng and the jpeg2000 libs installed on your system to enable png and jpg functionality in pygrib.

I chose ~/source/eccodes as the location to which I will tell cmake to install eccodes. ( nb: source is just a folder in my home directory where I install programs. You can choose any location: ~/<path-to-your-preferred-install-location>/eccodes)

The last line of the cmake command is the folder extracted from the tarball. (\ continues the command on a new line). For ease of readng purposes. While inside the 'build' directory, run:

cmake \
-DCMAKE_INSTALL_PREFIX=~/source/eccodes \ 
-ENABLE_NETCDF=OFF \
-ENABLE_JPG=OFF \
-ENABLE_PNG=OFF \
-ENABLE_PYTHON=OFF \
-ENABLE_FORTRAN=OFF \
../eccodes-2.8.2-Source

should you have any errors while building, delete the build folder and create it again, then (fix the issues) and run the cmake cmd again:

cd ..; rm -rf build; mkdir build; cd build

Note: If you get an error like -- Configuring incomplete, errors occurred! your makefile won't be created and you won't be able to run make in the next step. This could be because the cmake options you configured above (like ENABLE_PNG=OFF) were not properly loaded. Check the console output and if you see some defaults enabled which you disabled in the cmake command, then it means you're facing the same issue. This happened to me a few times and the only way I solved it was by changing the defaults manually inside the CMakeLists.txt. To do this (assuming you're still inside the build directory):

cd ..
cd eccodes-2.8.2-Source
nano CMakeLists.txt

then manually disable or enable whatever it is you need. Just look through the file for DEFAULT and adjust accordingly. For example, you change the ON to OFF for the option below.:

ecbuild_add_option( FEATURE JPG
    DESCRIPTION "Support for JPG decoding/encoding"
    DEFAULT ON
)

Save the file. Then delete and recreate your build directory as previously directed then run the cmake command again (no need to add the options since you've already changed them):

cmake -DCMAKE_INSTALL_PREFIX=~/source/eccodes ../eccodes-2.8.2-Source

It should now run successfully. You should see Configuring done. You now have a makefile and can continue.

When eccodes is done, run these commands

make
ctest

some of the tests may fail depending on the options (like the disabled dependency tests) you set for cmake, but if most ran fine then eccodes make went okay! Finish the make install with:

make install

you should now have eccodes fine on your machine. You will need to set this environment variable though:

export ECCODES_DEFINITION_PATH= the_path_to_where_you_told_cmake_to_install_eccodes/eccodes/share/eccodes/definitions. 

In my case:

nano ~/.bashrc

At the bottom of the file, add:

export ECCODES_DEFINITION_PATH=~/source/eccodes/share/eccodes/definitions

Press CTRL + X, then ENTER to save the file. Then source it to set the path in your current terminal session:

source ~/.bashrc

At this point eccodes should be set up A okay! Let's set up pygrib!

Pygrib Setup

I wouldn't recommend installing pygrib from pip (pypi) because,

  • it's behind the latest release
  • it will likely fail if you changed the default directories for eccodes and its environment variables

I recommend installing pygrib straight from the github: But first, a few necessary dependencies! pygrib needs numpy, matplotlib, basemap (which needs libgeos) Ensure you're still inside your virtualenv (venv). Your console should be showing it like this: (venv) user@computer:

Find the latest version of libgeos to install. In my case it was 3.6.2:

sudo apt-get install libgeos-3.6.2 libgeos-dev
pip install numpy matplotlib 
pip install https://github.com/matplotlib/basemap/archive/master.zip

Now if everything went well you should be able to install pygrib without any issues. We're going to install pygrib with pip but first we need to edit the setup file. From any directory. In my case, ~/source, get the latest pygrib master:

git clone https://github.com/jswhit/pygrib
cd pygrib

We need to create and edit the setup.cfg file. pygrib provides a template setup.cfg.template file for us. renaming the template file:

mv setup.cfg.template setup.cfg

In nano (or your favorite GUI text editor):

nano setup.cfg

In this file, find this line: #grib_api_dir = /usr/local

Uncomment and put the location of eccodes. in my case ~/source/eccodes (write the full path, in my case /home/emmanuel/source/eccodes):

grib_api_dir =/home/emmanuel/source/eccodes

In the latest version of eccodes, (>2.0.3), the default is #grib_api_libname = eccodes But if for some reason you're using (<2.0.3), uncomment the last line and ensure it is: grib_api_libname = eccodes

If you enabled any other dependencies (like jpg and png support) ensure you uncomment those lines to and point them to the install directory of those libraries.

To ensure smooth install, only uncomment what you need (I only have grib_api_dir uncommented). Everything else is disabled.

Save the file when you're done. In nano, CTRL+X then ENTER

You can optionally delete the .git folder. It is useless unless you're going to do a PR contribution on the pygrib project:

sudo rm -rf .git

Now we zip the contents of this folder to get it ready for a pip install:

zip -r ../pygrib.zip *

This places your zip file in the parent directory. Go up one to find it:

cd ..

Now we install it with pip (Are you still inside the venv? Ensure that you are!):

pip install pygrib.zip

If for some reason pip complains and refuses to install, fear not! You can build it and install it yourself:

  • copy the unzipped pygrib folder to your virtualenv's site-packages
  • again, ensure you're still in the venv:
cp -r pygrib/ ~/venv/lib/python3.6/site-packages/
cd ~/venv/lib/python3.6/site-packages/pygrib
python setup.py build
python setup.py install
python test.py 

If all goes well, then you're all set! You have successfully installed pygrib! Happy messing around with the world's meteorological data!

@mavengences
Copy link

Thanks for the info! Great step by step guide and was able to install pygrib successfully!

@rsingh16mi539
Copy link

what is source here?

@colineRamee
Copy link

Thanks a lot ! Worked for me on Ubuntu 16, python 3.5

@emmanuelnk
Copy link
Author

emmanuelnk commented Jul 24, 2019

what is source here?

What do you mean exactly? @rsingh16mi539. Sorry for the late reply. Hope you managed to get it to work

@Herman031
Copy link

Herman031 commented Nov 21, 2019

A very good step-by-step installation manual! One question regarding the step;

"Now we zip the contents of this folder to get it ready for a pip install:

zip -r ../pygrib.zip *"

I adjusted the path to my local situation;

zip -r /usr/local/mypackages/pygrib/pygrib.zip

but this returns a zip error;

"zip error: Nothing to do! (/usr/local/mypackages/pygrib/pygrib.zip)"

Your help is appreciated!

EDIT: Your workaround for pip worked, I skipped the zipping by using;

cp -r pygrib/ ~/venv/lib/python3.6/site-packages/
cd ~/venv/lib/python3.6/site-packages/pygrib
python setup.py build
python setup.py install
python test.py

Testing revealed a couple of options that I can tweak, but the most important thing that it works. Thanks again Emmanuel!

@preeth1
Copy link

preeth1 commented Nov 29, 2019

Thank you so much for this!!! I made it into a dockerfile, leaving it here in case this helps anyone else:

FROM python:3.7.3-stretch
RUN apt-get update &&\
    apt-get -y upgrade &&\
    apt-get install -y python3-pip python3-dev build-essential cmake gfortran zip apt-utils libgeos-dev wget &&\
    cd /usr/local &&\
    wget https://confluence.ecmwf.int/download/attachments/45757960/eccodes-2.15.0-Source.tar.gz?api=v2 &&\
    tar -xzf  eccodes-2.15.0-Source.tar.gz?api=v2 &&\
    mkdir build ; cd build &&\
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local -ENABLE_NETCDF=OFF -ENABLE_JPG=OFF -ENABLE_PNG=OFF -ENABLE_PYTHON=OFF -ENABLE_FORTRAN=OFF ../eccodes-2.15.0-Source &&\
    cd ../eccodes-2.15.0-Source &&\
    cd ..; rm -rf build; mkdir build; cd build &&\
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local ../eccodes-2.15.0-Source &&\
    make &&\
    make install &&\
    export ECCODES_DEFINITION_PATH=/usr/local/share/eccodes/definitions &&\
    git clone https://github.com/jswhit/pygrib &&\
    cd pygrib &&\
    touch setup.cfg &&\
    echo "[install_options]" >> setup.cfg &&\
    echo "[directories]" >> setup.cfg &&\
    echo "grib_api_dir = /root/source/eccodes" >> setup.cfg &&\
    echo "[files]" >> setup.cfg &&\
    rm -rf .git &&\
    zip -r ../pygrib.zip * &&\
    cd .. &&\
    pip install pygrib.zip &&\
    ldconfig &&\
    export LD_LIBRARY_PATH="/usr/local/eccodes-2.15.0-Source/build/lib:$LD_LIBRARY_PATH"
RUN python -c 'import pygrib'

# NOTE: THIS DIDNT WORK, but doesn't seem necessary for it to work: apt-get install libgeos-3.6.2

@emmanuelnk
Copy link
Author

Awesome stuff @preeth1 !!

@preeth1
Copy link

preeth1 commented Jan 7, 2020

Thanks!
By the way, I found that there is an eccodes distribution for ubuntu! So this Dockerfile also works:

FROM python:3.7.6-slim
RUN apt-get update &&\
    apt-get install -y libeccodes-dev gcc
RUN pip3 install pyproj
RUN pip3 install pygrib

And if you're on a mac, you just need to run brew install eccodes, pip install pyproj and then pip install pygrib will work!

@chikibot
Copy link

I get an systematic error with the "make" command for Eccodes.
At 75% (Generating gribapi/_gribapi_swig.so), I get :
fatal error: Python.h: No such file or directory
#include <Python.h>

It looks like Python.h causes a lot of trouble to many people, but none of the solutions I've seen proposed (install python3-dev, etc) seem to work.

Do you know how to solve this ?

@jpmacveigh
Copy link

Thanks for this informations.
It remains complicated for me to achive all this.
I would like to use Eccodes in AWS Lambda functions.
So, I need to add a layer in AWS Lambda containing Eccodes and all dependencies.
Could you provide a zip file containing all this as required by AWS Lambda ?
Thanks in advance.

@emmanuelnk
Copy link
Author

I get an systematic error with the "make" command for Eccodes.
At 75% (Generating gribapi/_gribapi_swig.so), I get :
fatal error: Python.h: No such file or directory
#include <Python.h>

It looks like Python.h causes a lot of trouble to many people, but none of the solutions I've seen proposed (install python3-dev, etc) seem to work.

Do you know how to solve this ?

Hi, did you solve it? Could you post more info about your environment. Did you ensure that you are using Python 3 and inside a python 3 virtualenv ? fatal error: Python.h: No such file or directory sounds like make can't find or is not using the correct Python. If you are not using virtualenv I'd highly advise to do so.

@emmanuelnk
Copy link
Author

emmanuelnk commented Feb 28, 2020

Thanks for this informations.
It remains complicated for me to achive all this.
I would like to use Eccodes in AWS Lambda functions.
So, I need to add a layer in AWS Lambda containing Eccodes and all dependencies.
Could you provide a zip file containing all this as required by AWS Lambda ?
Thanks in advance.

I meant to write a gist on this. Basically, I did it without layers. But I'll try to make a write up on both methods (and provide the necessary zip files). Ill try it tonight. In the meantime, you can try:

Using Docker

I haven't tested this but its worth a shot. Use the dockerfile posted in the above by preeth1 and convert it to a layer using this: https://github.com/awslabs/aws-lambda-container-image-converter and deploy it.

Without Layers (build binaries on EC2 instance and extract them)

  • create a nano ec2 instance using the Amazon Linux AMI image.
  • SSH into the ec2 and run this tutorial (install eccodes and pygrib).
  • Copy (using scp) the venv/lib/python3.6/site-packages folder (if you're using python virtualenv) to your machine. This is where all the relevant binaries needed to run pygrib on lambda will be.
  • You can copy the contents of site-packages (I'd remove all unnecessary packages to slim the size) to a folder called python_dependencies that will have all your required lambda python dependencies.
  • If you use serverless to deploy your lambdas, you can then just (from your project root): cp -r ./python_dependencies/* . && sls deploy
  • this is because the dependencies need to be at the root of your project (and subsequently lambda) to deploy correctly.

I'll see how to go about doing this with layers and update this. I'll also try to upload a sample dependency file.

@chikibot
Copy link

Started the whole installation from scratch, without virtual env. It works.
I'm now faced with another problem

> python3 -m eccodes selfcheck
Found: ecCodes v2.16.0.
Your system is ready.

But
> codes_info
ecCodes Version 2.6.0

Can't find that older version anywhere !
And the usual commands seem to refer to the older one

@wumpus
Copy link

wumpus commented Mar 11, 2020

This gist is very helpful! One thing it doesn't include (yet) is comments about Cython. I'm trying to build in macos with a brew-installed python 3.7.3, and the cython-generated .c files like pygrib.c (which is generated from pygrib.pyx) are not compatible with Python 3.7. OK, so that's not the python version you're aiming to explain, but here's the fix:

python setup.py build_ext --inplace

@hckaraman
Copy link

Thanks. That helped a lot.

@saguiMet
Copy link

saguiMet commented Apr 8, 2020

Hi!
warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it with "
^
pygrib.c: In function ‘__pyx_pf_6pygrib_6gaulats’:
pygrib.c:3239:10: warning: implicit declaration of function ‘grib_get_gaussian_latitudes’ [-Wimplicit-function-declaration]
(void)(grib_get_gaussian_latitudes(__Pyx_div_long(((long)__pyx_t_8), 2), ((double *)__pyx_v_lats->data)));
^
pygrib.c: In function ‘__pyx_pf_6pygrib_12julian_to_datetime’:
pygrib.c:7621:17: warning: implicit declaration of function ‘grib_julian_to_datetime’ [-Wimplicit-function-declaration]
__pyx_v_err = grib_julian_to_datetime(__pyx_v_julday, (&__pyx_v_year), (&__pyx_v_month), (&__pyx_v_day), (&__pyx_v_hour), (&__pyx_v_minute), (&__pyx_v_second));
^
pygrib.c: In function ‘__pyx_pf_6pygrib_14datetime_to_julian’:
pygrib.c:7874:17: warning: implicit declaration of function ‘grib_datetime_to_julian’ [-Wimplicit-function-declaration]
__pyx_v_err = grib_datetime_to_julian(__pyx_v_year, __pyx_v_month, __pyx_v_day, __pyx_v_hour, __pyx_v_minute, __pyx_v_second, (&__pyx_v_julday));
^
pygrib.c: In function ‘__pyx_pf_6pygrib_11gribmessage_16keys’:
pygrib.c:13964:58: error: ‘GRIB_KEYS_ITERATOR_ALL_KEYS’ undeclared (first use in this function)
__pyx_v_gi = grib_keys_iterator_new(__pyx_v_self->_gh, GRIB_KEYS_ITERATOR_ALL_KEYS, NULL);
^
pygrib.c:13964:58: note: each undeclared identifier is reported only once for each function it appears in
pygrib.c:13996:18: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
__pyx_v_name = grib_keys_iterator_get_name(__pyx_v_gi);
^
pygrib.c: In function ‘__pyx_pf_6pygrib_11gribmessage_18_read_only_keys’:
pygrib.c:14427:18: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
__pyx_v_name = grib_keys_iterator_get_name(__pyx_v_gi);
^
pygrib.c: In function ‘__pyx_pf_6pygrib_11gribmessage_30tostring’:
pygrib.c:18559:53: warning: passing argument 2 of ‘grib_get_message’ from incompatible pointer type [-Wincompatible-pointer-types]
__pyx_v_err = grib_get_message(__pyx_v_self->_gh, (&__pyx_v_message), (&__pyx_v_size));
^
In file included from pygrib.c:614:0:
grib_api.h:82:5: note: expected ‘const void *’ but argument is of type ‘void
int grib_get_message(const grib_handle
h ,const void
message, size_t *message_length);
^
pygrib.c: In function ‘__pyx_pf_6pygrib_11gribmessage_34_reshape_mask’:
pygrib.c:19604:36: error: ‘GRIB_MISSING_LONG’ undeclared (first use in this function)
__pyx_t_2 = __Pyx_PyInt_From_int(GRIB_MISSING_LONG); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1386, __pyx_L1_error)
^
pygrib.c: In function ‘__pyx_pymod_exec_pygrib’:
pygrib.c:35680:3: warning: return makes integer from pointer without a cast [-Wint-conversion]
import_array();
^
pygrib.c:35698:36: error: ‘GRIB_MISSING_LONG’ undeclared (first use in this function)
__pyx_t_1 = __Pyx_PyInt_From_int(GRIB_MISSING_LONG); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 295, __pyx_L1_error)
^
error: command 'gcc' failed with exit status 1


What is wrong?
Please!

@emmanuelnk
Copy link
Author

@saguiMet,
what command did you run to produce this error? (what step of the setup is it failing?)
Also, could you please provide more information about your system:

  • os distribution and version
  • python version (ensure its python 3.6.5 or greater)
  • eccodes version
  • pygrib version
  • make and cmake versions

@saguiMet
Copy link

saguiMet commented Apr 9, 2020

I was following your script. I stoped in: 'python setup.py build'
ubuntu 16.04
python 3.7.6
eccodes 2.16.0
cmake 3.17.0
make 4.1

@emmanuelnk
Copy link
Author

emmanuelnk commented Apr 9, 2020

@saguiMet

Is the setup.cfg file created correctly and pointing to the correct path for eccodes? And if so do you have these two lines in your setup.cfg ?

...
grib_api_dir =/home/$USER/source/eccodes # your path for eccodes
grib_api_libname = eccodes
...

Can you post the contents of that file? Also, where is your eccodes installed (path)?

@saguiMet
Copy link

saguiMet commented Apr 9, 2020

setup.cfg:
#grib_api_dir = /usr/local/home/desktop/source/eccodes
#grib_api_libname = eccodes

eccodes path:
venv/lib/python3.7/packages/pygrib/

@calvin272m
Copy link

hey, I followed the instruction to install eccodes and pygrid on my computer, mac os Catalina.
firstly, I did uncomment the setup.cfg by removing the # and changing the grib_api_dir= /Users/.../ecoodes where I put the eccodes in. and also the last line into grib_api_libname = eccodes.
I also met issues firstly at pip install pygrib. it say the setup.py line 194, path didn't define.
then I copy the pygrib.zip to python3.7/site-packages,
tried to use python setup.py build, still meet the issue mentioned above. then I change the setup.py file, line 194, from path to os.path.
then it raised the issued encountered by saguiMet," error: command 'gcc' failed with exit status 1"

I tried at least thousands of times to install it, but everytime it failed somewhere in the process.
i cannot use the sudo apt-get, so I used brew instead.
also I cannot install build-essential, which is not contained in the Homebrew packages. also I failed to install python3-dev, later I can only use brew to install geos, instead of libgeos, also I installed eccodes-2.17.0-Source. for the rest, I think I managed to follow what you wrote in the instruction. I don't really know how to fix the issue now. and also the conda install -c conda-forge pygrib, /python-ecmwf_grib doesn't work in my anaconda environment, which says my python 3.7 is not
Specifications:

  • python-ecmwf_grib -> python[version='2.7.|>=2.7,<2.8.0a0|3.5.|3.4.*']

Your python: python=3.7

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.

also, I heard my peer used the conda install for linux and virtual machine of windows ten.
but mine is mac os. hope someone could kindly help me out? Thanks.

@emmanuelnk
Copy link
Author

emmanuelnk commented Apr 20, 2020

@calvin272m

Did you try the method by Preeth1 for installing on a mac?

brew install eccodes
pip install pyproj
pip install pygrib

If the above fails what about installing it using docker?

@w142236
Copy link

w142236 commented Sep 8, 2020

Hi! I have never used linux before for installing packages so forgive me if this sounds dumb.
I have successfully installed pygrib using ubuntu. I typed pip list and verified that it is there. If I open Spyder and type import pygrib, I get an error saying that the package is not installed.
Is this to be expected or did I do something wrong?

@emmanuelnk
Copy link
Author

Hi! I have never used linux before for installing packages so forgive me if this sounds dumb.
I have successfully installed pygrib using ubuntu. I typed pip list and verified that it is there. If I open Spyder and type import pygrib, I get an error saying that the package is not installed.
Is this to be expected or did I do something wrong?

Are you sure you're using the same environment you installed pygrib in? For example if you followed my tutorial, you would have installed pygrib to a virtual python environment called venv .. Maybe the environment is not activated and you end up using your system's python instead which does not have pygrib installed. I'd check this out.

@w142236
Copy link

w142236 commented Sep 11, 2020

Hi! I have never used linux before for installing packages so forgive me if this sounds dumb.
I have successfully installed pygrib using ubuntu. I typed pip list and verified that it is there. If I open Spyder and type import pygrib, I get an error saying that the package is not installed.
Is this to be expected or did I do something wrong?

Are you sure you're using the same environment you installed pygrib in? For example if you followed my tutorial, you would have installed pygrib to a virtual python environment called venv .. Maybe the environment is not activated and you end up using your system's python instead which does not have pygrib installed. I'd check this out.

Ah! I was not. The IDE, Spyder, which was installed to my computer via Anaconda was not installed into the virtual environment.
I decided to try making a simple script using nano whatever_name.py in my home directory after activating the virtual environment and I just ran import pygrib and it worked just fine.
I further tested it by running:
file = 'hrrr.t00z.wrfsfcf00.grib2'
gr = pygrib.open(file)
for g in gr:
print(g)
and it ran perfectly.
The problem I have now is that I have no idea what the names of the parameters are for the grib object I've created (which is the benefit of using the IDE). Is there anyway that I can install an IDE in the virtualenv on Ubuntu and then run it from there, or am I stuck making my scripts in the nano editor?
Thank you!

@emmanuelnk
Copy link
Author

Hi! I have never used linux before for installing packages so forgive me if this sounds dumb.
I have successfully installed pygrib using ubuntu. I typed pip list and verified that it is there. If I open Spyder and type import pygrib, I get an error saying that the package is not installed.
Is this to be expected or did I do something wrong?

Are you sure you're using the same environment you installed pygrib in? For example if you followed my tutorial, you would have installed pygrib to a virtual python environment called venv .. Maybe the environment is not activated and you end up using your system's python instead which does not have pygrib installed. I'd check this out.

Ah! I was not. The IDE, Spyder, which was installed to my computer via Anaconda was not installed into the virtual environment.
I decided to try making a simple script using nano whatever_name.py in my home directory after activating the virtual environment and I just ran import pygrib and it worked just fine.
I further tested it by running:
file = 'hrrr.t00z.wrfsfcf00.grib2'
gr = pygrib.open(file)
for g in gr:
print(g)
and it ran perfectly.
The problem I have now is that I have no idea what the names of the parameters are for the grib object I've created (which is the benefit of using the IDE). Is there anyway that I can install an IDE in the virtualenv on Ubuntu and then run it from there, or am I stuck making my scripts in the nano editor?
Thank you!

Since Spyder is using Anacondas python, all you have to do is activate the anaconda python environment that spyder uses.
check the conda envs you have

conda env list

Activate your default conda env

conda activate 

or

conda activate myenv 

Once your conda environment is activated in your terminal, proceed to install pygrib in the same terminal (thus installing pygrib to this environment instead of venv).
I believe spyder should then be able to find pygrib.

See this reference: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

@w142236
Copy link

w142236 commented Sep 21, 2020

Hi! I have never used linux before for installing packages so forgive me if this sounds dumb.
I have successfully installed pygrib using ubuntu. I typed pip list and verified that it is there. If I open Spyder and type import pygrib, I get an error saying that the package is not installed.
Is this to be expected or did I do something wrong?

Are you sure you're using the same environment you installed pygrib in? For example if you followed my tutorial, you would have installed pygrib to a virtual python environment called venv .. Maybe the environment is not activated and you end up using your system's python instead which does not have pygrib installed. I'd check this out.

Ah! I was not. The IDE, Spyder, which was installed to my computer via Anaconda was not installed into the virtual environment.
I decided to try making a simple script using nano whatever_name.py in my home directory after activating the virtual environment and I just ran import pygrib and it worked just fine.
I further tested it by running:
file = 'hrrr.t00z.wrfsfcf00.grib2'
gr = pygrib.open(file)
for g in gr:
print(g)
and it ran perfectly.
The problem I have now is that I have no idea what the names of the parameters are for the grib object I've created (which is the benefit of using the IDE). Is there anyway that I can install an IDE in the virtualenv on Ubuntu and then run it from there, or am I stuck making my scripts in the nano editor?
Thank you!

Since Spyder is using Anacondas python, all you have to do is activate the anaconda python environment that spyder uses.
check the conda envs you have

conda env list

Activate your default conda env

conda activate 

or

conda activate myenv 

Once your conda environment is activated in your terminal, proceed to install pygrib in the same terminal (thus installing pygrib to this environment instead of venv).
I believe spyder should then be able to find pygrib.

See this reference: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

But wasn't the point of installing this with ubuntu so that I could bypass installing pygrib with anaconda prompt or windows command prompt? No one can seem to install pygrib without using Linux.

Anyways, I tried uncompressing the eccodes and I got a series of errors saying that it "Can't create '\\?\C:\Users\willk\pygrib\eccodes\eccodes-2.8.2-Source\definitions\mars\whatever'" and the same for samedirectory\definitions\grib1\whatever
I skipped the steps of installing build-essential and cmake because I could not find the Python equivalent of them and that is likely what is causing the error.

@saguiMet
Copy link

saguiMet commented Oct 9, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment