Skip Navigation Links 
NOAA logo - Click to go to the NOAA home page National Weather Service   NWS logo - Click to go to the NWS home page
Climate Prediction Center

About Us
   Our Mission
   Who We Are

Contact Us
   CPC Information
   CPC Web Team

HOME > Monitoring_and_Data > Oceanic and Atmospheric Data > Reanalysis: Atmospheric Data > pywgrib2_s: installation



  1. python 3.5+, numpy
  2. Linux (tested: Ubuntu, Redhat, SUSE), MacOS
  3. wgrib2 v3.0.2+ shared library


    Step 1: Make or obtain a wgrib2 shared library
  1. To make the wgrib2 shared library
  2. cd to the directory where you want to place the wgrib2 source code: cd XYZ
  3. get the latest source code to wgrib2 (wgrib2.tgz):
  4. $ wget ""
  5. untar the source code: $ tar -xzvf wgrib2.tgz
  6. cd to the grib2 directory: $ cd grib2
  7. edit makefile, change "MAKE_SHARED_LIB=0" to "MAKE_SHARED_LIB=1"
  8. optional edit makefile to user customizations
  9. set the C and fortran compilers (must be gcc and gfortran), this is the bash compile
  10. $ export CC=gcc
  11. $ export FC=gfortran
  12. $ make lib
  13. check for the shared library, linux: lib/, mac: lib/libwgrib2.dylib
    Step 2: find a directory on the python path (PYDIR)
  1. try .local/lib/pythonN.M/site-packages/ N.M = python version N.M >= 3.5 (lowest version tested)
       # .local/lib/pythonN.M/site-packages will not appear on search path unless already created
       mkdir -p .local/lib/pythonN.M/site-packages
  2. query python for directories
       >>> import sys
       >>> sys.path
  3. The above script will not show missing directories on the path.
  4. Choose an appropriate directory with write permission.
  5. If you cannot find a writable directory, change the python path to create such a directory.
    Step 3: Get PYDIR
  1. download
  2. extract contents, tar -xzvf pywgrib2_s.tgz
    Step 4: install wgrib2 shared library
  1. shared library is named (use libwgrib2.dylib for Darwin)
  2. for pywgrib2_s version 0.0.x, copy shared wgrib2 lib to PYDIR
  3. pywgrib2_s 1.0.0+ has a search order for the shared library.
    1. name of shared library is given by environment varible $WGRIB2_LIB
    2. shared library ( is saved in PYDIR
    3. shared library ( is found in system defined library
    Step 5: test using the cookbook
  1. wget
  2. Try running the cookbook_*.py scripts from the shell.

Multiple versions of shared wgrib2 library:

The libraries used by pywgrib2_s may conflict with those used by the calling program. In such cases, you have to compile wgrib2 without the offending libraries. This may reduce the functionality of pywgrib2_s/wgrib2 but you will have to work around this problem. The end result can be multiple versions of In such cases, the environment variable $WGRIB2_LIB will have to be used to specify except for the default library.

System Installations

The above instructions suggested that .local/lib/pythonN.M/site-packages may work for PYDIR. This suggestion is for an person to install on one's account. For a system install, you need to be root and place it in a root owned directory on the python path.

See also:

NOAA/ National Weather Service
National Centers for Environmental Prediction
Climate Prediction Center
5830 University Research Court
College Park, Maryland 20740
Climate Prediction Center Web Team
Created: Aug 11, 2020, Modified: Oct 6, 2020, June 2021. 11/2022
Disclaimer Privacy Policy