pyhdf
pyhdf copied to clipboard
Failed import -`from pyhdf import SD` on Google Collab
What version of pyhdf, HDF4, and Python are you using?
pyhdf version: 0.10.5 HDF4 C library version: libhdf4-4.2.13 Python version: 3.8.16
What operating system are you using?
GNU/Linux (Google Collab)
What did you do?
!pip install pyhdf
from pyhdf import SD
What did you expect to see?
The import is successful
What did you see instead?
The import breaks with:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
RuntimeError: module compiled against API version 0xf but this version of numpy is 0xe
---------------------------------------------------------------------------
SystemError Traceback (most recent call last)
[<ipython-input-20-9e0d221b6649>](https://localhost:8080/#) in <module>
1 get_ipython().system('pip install pyhdf')
----> 2 from pyhdf import SD
3 frames
[/usr/local/lib/python3.8/dist-packages/pyhdf/SD.py](https://localhost:8080/#) in <module>
1001 import os, sys, types
1002
-> 1003 from . import hdfext as _C
1004 from .six.moves import xrange
1005 from .error import _checkErr, HDF4Error
[/usr/local/lib/python3.8/dist-packages/pyhdf/hdfext.py](https://localhost:8080/#) in <module>
15 except ImportError:
16 return importlib.import_module('_hdfext')
---> 17 _hdfext = swig_import_helper()
18 del swig_import_helper
19 elif _swig_python_version_info >= (2, 6, 0):
[/usr/local/lib/python3.8/dist-packages/pyhdf/hdfext.py](https://localhost:8080/#) in swig_import_helper()
12 mname = '.'.join((pkg, '_hdfext')).lstrip('.')
13 try:
---> 14 return importlib.import_module(mname)
15 except ImportError:
16 return importlib.import_module('_hdfext')
[/usr/lib/python3.8/importlib/__init__.py](https://localhost:8080/#) in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128
129
SystemError: initialization of _hdfext raised unreported exception
Numpy in google colab is a couple versions out of date which causes these issues. At the top of your notebook you can add a
!pip install --upgrade numpy==1.22.4 pyhdf
which seems to satisfy the rest of the environment and work for the built distribution of pyhdf. You'll have to restart the runtime though to replace the auto-imported numpy. Colab will warn about this.