1

I am trying to install netCDF4==1.4.2 using "pip install netCDF4==1.4.2" to use in jupyter notebook.

I am running

Windows 10 enterprise 64 bit.
python                        3.10.9
anaconda-client               1.11.2
anaconda-navigator            2.4.0
anaconda-project              0.11.1
conda                         23.3.1
conda-build                   3.24.0
conda-content-trust           0.1.3
conda-pack                    0.6.0
conda-package-handling        2.0.2
conda_package_streaming       0.7.0
conda-repo-cli                1.0.41
conda-token                   0.4.0
conda-verify                  3.4.2
ipykernel                     6.19.2
ipython                       8.10.0
ipython-genutils              0.2.0
ipywidgets                    7.6.5
jupyter                       1.0.0
jupyter_client                7.3.4
jupyter-console               6.6.2
jupyter_core                  5.2.0
jupyter-server                1.23.4
jupyterlab                    3.5.3
jupyterlab-pygments           0.1.2
jupyterlab_server             2.19.0
jupyterlab-widgets            1.0.0
pip                           23.2

But, I am getting this error when using the Anaconda Prompt.

(base) C:\\Users\\79\>pip install netCDF4==1.4.2

Collecting netCDF4==1.4.2
Using cached netCDF4-1.4.2.tar.gz (769 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─\> \[19 lines of output\]
C:\\Users\\79\\AppData\\Local\\Temp\\pip-install-2bd1mj_1\\netcdf4_e3f1e4ce8f52415499486dd692dea5ae\\setup.py:170: DeprecationWarning: The SafeConfigParser class has been renamed to ConfigParser in Python 3.2. This alias will be removed in Python 3.12. Use ConfigParser directly instead.
config = configparser.SafeConfigParser()
Traceback (most recent call last):
File "\<string\>", line 2, in \<module\>
File "\<pip-setuptools-caller\>", line 34, in \<module\>
File "C:\\Users\\79\\AppData\\Local\\Temp\\pip-install-2bd1mj_1\\netcdf4_e3f1e4ce8f52415499486dd692dea5ae\\setup.py", line 371, in \<module\>
\_populate_hdf5_info(dirstosearch, inc_dirs, libs, lib_dirs)
File "C:\\Users\\79\\AppData\\Local\\Temp\\pip-install-2bd1mj_1\\netcdf4_e3f1e4ce8f52415499486dd692dea5ae\\setup.py", line 319, in \_populate_hdf5_info
raise ValueError('did not find HDF5 headers')
ValueError: did not find HDF5 headers
reading from setup.cfg...

          HDF5_DIR environment variable not set, checking some standard locations ..
      checking C:\Users\79 ...
      checking /usr/local ...
      checking /sw ...
      checking /opt ...
      checking /opt/local ...
      checking /usr ...
      [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─\> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

I have tried suggestions in this post Installing specific package version with pip to no avail. And https://betterdatascience.com/pip-install-specific-version/. Which was basically updating setuptools, installing ez_isntall, and install unroll (which didn't work).

The same issue occurs if I try to install it through the settings in pycharm. Not too sure what is going on.

mathnoob
  • 15
  • 5

1 Answers1

1

netCDF4 1.4.2 provides wheels for Python 2.7 and 3 up to 3.7. You have Python 3.10 so pip is trying to compile netCDF4 from sources but that requires sources (esp. headers) for HDF5.

Either install HDF5 headers and libraries and compile netCDF4. Or downgrade Python to 3.7, then pip could use pre-compiled wheel from PyPI. Or use higher version of netCDF4; netCDF4 1.5.8 and higher provide wheels for Python 3.10; the current latest version 1.6.4.

phd
  • 82,685
  • 13
  • 120
  • 165
  • Hi, Thank you for your reply. Should I download the latest HDF5? I am using this link [HDF Group Website](https://www.hdfgroup.org/downloads/hdf5/). I think I might be confused on what headers and libraries are when it pertains to packages. – mathnoob Jul 24 '23 at 17:14
  • My advice is to use precompiled wheels of `netCDF4`; downgrade Python to 3.7, then `pip` could use pre-compiled wheel from PyPI. Or use higher version of `netCDF4`. Compiling it from sources is hard. See the instructions at https://unidata.github.io/netcdf4-python/#developer-install – phd Jul 24 '23 at 18:02
  • So, this is a bit weird. I downgraded to python 2.7 to match the version that the author was using. What I did was installed all of the packages here except netcdf4 and netcdftime as I got errors when installing them still. They are: numpy==1.15.4, pandas==0.24.1, scipy==1.2.0, netcdf4==1.4.2, matplotlib==2.2.3, xarray==0.11.3, statsmodels==0.9.0, cftime==1.0.3.4, netcdftime==1.0.0a2, dask==1.1.1, toolz==0.9.0, AND setuptools==41.2.0. THEN, I was able to install netcdf4==1.4.2. I am now having trouble with netcdftime==1.0.0a2. Python 2.7 had wheel==0.37.1 and pip==20.3.4 preinstalled. – mathnoob Jul 25 '23 at 03:20
  • I still want to go the route you had advised. By using precompiled wheels of netCDF4; downgrade Python to 3.7, then pip could use pre-compiled wheel from PyPI. But, I'm not too sure what "precompiled wheels of netCDF4 means." – mathnoob Jul 25 '23 at 03:23
  • For netcdftime==1.0.0a2. I installed cython==0.28.5 and installed Microsoft Visual C++ 9.0. [https://stackoverflow.com/questions/43645519/microsoft-visual-c-9-0-is-required](Download the archived version of Microsoft Visual C++ Compiler for Python 2.7 from the following link:). Look for the comment that points to the archived link. – mathnoob Jul 25 '23 at 03:33