错误:numpy.core.multiarray无法导入pyhdf

w1e3prcc  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(150)

我尝试使用本网站提供的python代码(https://hdfeos.org/software/pyhdf.php)打开HDF文件。但是,在导入pyhdf包时出现错误

import os
from pyhdf.SD import SD, SDC
import numpy as np
import rasterio

字符串
错误:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf . Check the section C-API incompatibility at the Troubleshooting ImportError section at https://numpy.org/devdocs/user/troubleshooting-importerror.html#c-api-incompatibility for indications on how to solve this problem .
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [14], in <cell line: 2>()
      1 import os
----> 2 from pyhdf.SD import SD, SDC
      3 import rasterio

File ~\Miniconda3\lib\site-packages\pyhdf\SD.py:1003, in <module>
     38 """
     39 SD (scientific dataset) API (:mod:`pyhdf.SD`)
     40 =============================================
   (...)
    999 
   1000 """
   1001 import os, sys, types
-> 1003 from . import hdfext as _C
   1004 from .six.moves import xrange
   1005 from .error import _checkErr, HDF4Error

File ~\Miniconda3\lib\site-packages\pyhdf\hdfext.py:10, in <module>
      8 # Import the low-level C/C++ module
      9 if __package__ or "." in __name__:
---> 10     from . import _hdfext
     11 else:
     12     import _hdfext

ImportError: numpy.core.multiarray failed to import


我尝试升级numpy和pyhdf版本,但它没有工作

kxkpmulp

kxkpmulp1#

正如@Cow评论的那样,我把这篇文章作为回答:

The following packages are required to build and install pyhdf:

Python: Python 2.6 or newer for Python 2, or Python 3.2 or newer for Python 3.

NumPy

HDF4 libraries (to use their HDF4 binaries, you will also need szip, available from the same page)

Compiler suite e.g. GCC. On Windows, you need to use a compatible Visual C++ compiler.

zlib

libjpeg

字符串
https://fhs.github.io/pyhdf/install.html#requirements
特别注意Swig生成的接口文件
接口文件hdfext.py和hdfext_wrap.c(位于pyhdf目录下)已经使用SWIG工具生成。这两个文件应该可以在大多数环境中使用。但是,由于与您的环境相关的原因,可能会发生C编译器不接受“.c”文件并引发编译错误。如果是这样,则需要重新生成接口。为此,请安装SWIG,然后运行:

$ cd pyhdf
$ swig -python hdfext.i


SWIG应该静默地重新生成这两个接口文件,然后安装应该正确地进行。
https://fhs.github.io/pyhdf/install.html#swig-generated-interface-files

相关问题