pythonpython-2.7pygrib

importing pygrib in python


In spite encountering no errors in pygrib installation, I encountered the following error when importing pygrib:

>>> import pygrib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: /python/python-2.7.13/lib/python2.7/site-packages/pygrib.so: undefined symbol: __svml_round2_mask

Any advice on what could be causing this "undefined symbol" error?


Solution

  • Undefined symbol errors are usually caused by one of two things:

    Incorrect linking

    If you are building the pygrib module itself, make sure that the required library dependencies are being properly linked, and in the right order. Based on the missing symbol name, __svml_round2_mask, I'd guess your pygrib.so was compiled with the Intel icc C compiler and needs to be linked to the math library containing the SVML (Short Vector Math Library) functions. It's difficult to get more specific without knowing more details of your build environment, but for example, on linux, both icc and gcc (which both call GNU ld for linking) need to have that math library specified on their command line, and it needs to come after the binary or library that is calling it.

    Evironment mismatch

    If pygrib is not being built by you (either explicitly, or as part of a pip or conda install command), then you probably have an environment mismatch. This happens when the pygrib.so you downloaded was built against different libraries than the ones you have installed. Ideally, all Python binary packages would be built against a very vanilla set of libraries (e.g. the "manylinux1" container for linux wheels) so that they will run on most systems, but sometimes specialized and performance-critical packages need to be built with particular optimizations or against uncommon libraries. If those optimizations or libraries don't match between the build system and the system on which the resulting package is install, the undefined symbol error can be the result.

    One way to minimize the occurrence of this is to not mix-and-match package repositories where possible. That is, if you're using Anaconda, only pull packages from Anaconda. I know, not always possible, right?

    If you're on linux, it is sometimes possible to figure out where the mismatch is by using the ldd command, for example:

    $ ldd -r /python/python-2.7.13/lib/python2.7/site-packages/pygrib.so

    You'll see a bunch of undefined symbols starting with Py or _Py--ignore those, they're supplied by Python itself. But in amongst those, you'll hopefully discover which particular library is needing __svml_round2_mask. Look at its full path carefully, and the full paths of the other libraries listed, and this might suggest where the mismatch came from.

    Other suggestions

    Good luck, I hope something in here helps!