无法在windows上通过pip安装netCDF4

问题描述 投票:0回答:3

我刚刚在 Windows 10 上安装了“vanilla”python 并尝试安装 netCDF4,却发现它给出了一个错误: “ValueError:未找到 HDF5 标头”

这是Python 3.7,版本如下:

py -m pip list
Package            Version
------------------ -------
attrs              19.1.0
backcall           0.1.0
bleach             3.1.0
bokeh              1.3.4
colorama           0.4.1
cycler             0.10.0
Cython             0.29.13
decorator          4.4.0
defusedxml         0.6.0
entrypoints        0.3
h5py               2.9.0
ipykernel          5.1.2
ipython            7.8.0
ipython-genutils   0.2.0
ipywidgets         7.5.1
jedi               0.15.1
Jinja2             2.10.1
jsonschema         3.0.2
jupyter            1.0.0
jupyter-client     5.3.1
jupyter-console    6.0.0
jupyter-core       4.5.0
kiwisolver         1.1.0
MarkupSafe         1.1.1
matplotlib         3.1.1
mistune            0.8.4
nbconvert          5.6.0
nbformat           4.4.0
notebook           6.0.1
numpy              1.17.1
packaging          19.1
pandas             0.25.1
pandocfilters      1.4.2
parso              0.5.1
pickleshare        0.7.5
Pillow             6.1.0
pip                19.2.3
pip-review         1.0
pivottablejs       0.9.0
prometheus-client  0.7.1
prompt-toolkit     2.0.9
Pygments           2.4.2
pyparsing          2.4.2
pypl               40.10
pyrsistent         0.15.4
python-dateutil    2.8.0
pytz               2019.2
pywinpty           0.5.5
PyYAML             5.1.2
pyzmq              18.1.0
qtconsole          4.5.5
scipy              1.3.1
seaborn            0.9.0
Send2Trash         1.5.0
setuptools         41.2.0
six                1.12.0
svgwrite           1.3.1
terminado          0.8.2
testpath           0.4.2
tornado            6.0.3
traitlets          4.3.2
virtualenv         16.7.5
wcwidth            0.1.7
webencodings       0.5.1
widgetsnbextension 3.5.1
xarray             0.12.3

当我尝试使用 pip 安装 netCDF 时,出现错误。 整个错误信息是:

>py -m pip install netCDF4
Collecting netCDF4
  Using cached 

 https://files.pythonhosted.org/packages/64/2e/abc0bce095ab5a3b8374f052ace2509a031fd7633b23917e557487067225/netCDF4-1.5.2.tar.gz
    ERROR: Command errored out with exit status 1:
     command: 'c:\python37-32\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\***\\AppData\\Local\\Temp\\pip-install-374v_ecc\\netCDF4\\setup.py'"'"'; __file__='"'"'C:\\Users\\***\\AppData\\Local\\Temp\\pip-install-374v_ecc\\netCDF4\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: C:\Users\***\AppData\Local\Temp\pip-install-374v_ecc\netCDF4\
    Complete output (16 lines):
    reading from setup.cfg...

        HDF5_DIR environment variable not set, checking some standard locations ..
    checking C:\Users\***...
    checking /usr/local ...
    checking /sw ...
    checking /opt ...
    checking /opt/local ...
    checking /usr ...
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\***\AppData\Local\Temp\pip-install-374v_ecc\netCDF4\setup.py", line 397, in <module>
        _populate_hdf5_info(dirstosearch, inc_dirs, libs, lib_dirs)
      File "C:\Users\***\AppData\Local\Temp\pip-install-374v_ecc\netCDF4\setup.py", line 345, in _populate_hdf5_info
        raise ValueError('did not find HDF5 headers')
    ValueError: did not find HDF5 headers
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

请告诉我该怎么做或您需要什么信息。 谢谢。

python windows
3个回答
2
投票

我自己解决了这个问题。 我需要手动安装 C++ 编译器,因为它不包含在 vanilla python 包中(当然)。

我从以下网站下载并安装了“Visual Studio 构建工具”: https://visualstudio.microsoft.com/downloads/ 这解决了问题。


2
投票

TL;DR:如果遇到此问题,请检查当前的 h5py 轮子是否存在问题

今天下午我刚刚遇到了与OP几乎完全相同的问题,并花了最后一个小时将我的头撞在墙上。

我的故事:

  1. 我正在使用Python 3.11.1
  2. 找到了这个帖子。我似乎遇到了与 OP 相同的问题
  3. 我考虑安装 Visual Studio 的构建工具,但注意到它大约有 5 GB...
  4. 决定进一步调查
  5. 发现这个 GitHub 问题 证明这是 3.11.1 的 h5py 轮子的问题
  6. 使用 Python 3.8.3 在另一台计算机上安装 netCDF4,没有任何问题
  7. 我将使用Python<=3.10 until h5py wheel is sorted

那么 C++ 编译器是 OP 问题的真正解决方案吗?好吧,我检查了一下,结果发现,早在 2019 年 9 月,就存在“车轮未解决的另一个问题”,该问题在 OP 发表第一篇文章时已关闭。不过,时间线上似乎有大约 23 小时的差距(我认为我已经正确地考虑了时区)。也许 C++ 编译器能够解决由故障轮带来的问题?


0
投票
可用

下载与Python版本和操作系统平台相匹配的wheel文件后,

pip install <THE WHEEL FILE JUST DOWNLOADED>

    

© www.soinside.com 2019 - 2024. All rights reserved.