Fail to install MNE-connectivity, ValueError: did not find netCDF version 4 headers

  • MNE version: 1.2.3
  • operating system: Windows 10

Hello,

When I install mne-connectivity in my laptop using pip install --user mne-connectivity, I ran into an error:

Collecting mne-connectivity
  Using cached https://files.pythonhosted.org/packages/88/59/bcdb53563328730661be16b87c5f83c5d1cdae2d7a38e94b5b4a7732e5eb/mne_connectivity-0.4.0-py3-none-any.whl
Requirement already satisfied: xarray in c:\users\user\appdata\roaming\python\python37\site-packages (from mne-connectivity) (0.18.0)
Requirement already satisfied: numpy in c:\users\user\appdata\roaming\python\python37\site-packages (from mne-connectivity) (1.21.6)
Collecting netCDF4 (from mne-connectivity)
  Using cached https://files.pythonhosted.org/packages/a6/f9/12f43c2e31d1c7aae0827820ae747fa4c7cc382b38dab11e8c11575d3af6/netCDF4-1.6.2.tar.gz
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'error'
Note: you may need to restart the kernel to use updated packages.
  ERROR: Complete output from command 'C:\Users\user\Anaconda3\pythonw.exe' 'C:\Users\user\Anaconda3\lib\site-packages\pip\_vendor\pep517\_in_process.py' get_requires_for_build_wheel 'C:\Users\user\AppData\Local\Temp\tmpl2xyiq_j':
  ERROR: reading from setup.cfg...
  
      HDF5_DIR environment variable not set, checking some standard locations ..
  checking C:\Users\user\Anaconda3\include ...
  hdf5 headers not found in C:\Users\user\Anaconda3\include
  checking C:\Users\user\Anaconda3\Library\include ...
  HDF5 library version: 1.10.4 headers found in C:\Users\user\Anaconda3\Library\include
  HDF5 library version: 1.10.4 found in C:\Users\user\Anaconda3\Library
  
  NETCDF4_DIR environment variable not set, checking standard locations..
  checking C:\Users\user\Anaconda3 ...
  checking C:\Users\user\Anaconda3\Library ...
  checking C:\Users\user ...
  checking /usr/local ...
  checking /sw ...
  checking /opt ...
  checking /opt/local ...
  checking /opt/homebrew ...
  checking /usr ...
  Traceback (most recent call last):
    File "C:\Users\user\Anaconda3\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 207, in <module>
      main()
    File "C:\Users\user\Anaconda3\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 197, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "C:\Users\user\Anaconda3\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 54, in get_requires_for_build_wheel
      return hook(config_settings)
    File "C:\Users\user\AppData\Local\Temp\pip-build-env-fcrazn8c\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
    File "C:\Users\user\AppData\Local\Temp\pip-build-env-fcrazn8c\overlay\Lib\site-packages\setuptools\build_meta.py", line 320, in _get_build_requires
      self.run_setup()
    File "C:\Users\user\AppData\Local\Temp\pip-build-env-fcrazn8c\overlay\Lib\site-packages\setuptools\build_meta.py", line 335, in run_setup
      exec(code, locals())
    File "<string>", line 465, in <module>
  ValueError: did not find netCDF version 4 headers
  ----------------------------------------
ERROR: Command "'C:\Users\user\Anaconda3\pythonw.exe' 'C:\Users\user\Anaconda3\lib\site-packages\pip\_vendor\pep517\_in_process.py' get_requires_for_build_wheel 'C:\Users\user\AppData\Local\Temp\tmpl2xyiq_j'" failed with error code 1 in C:\Users\user\AppData\Local\Temp\pip-install-touo5cli\netCDF4

How can I solve this problem? Thanks!

can you try installing netCDF4 directly first, like this?

pip install netcdf4 --no-cache-dir --force-reinstall

If that works, then probably the problem was a corrupted archive of netcdf4 in the pip cache.

1 Like

Since you’re using Anaconda, you can also just install it into a fresh environment via:

conda create --name=mne --channel=conda-forge --strict-channel-priority mne-connectivity

FYI you should try to avoid passing the --user switch to pip, I’ve seen it cause nothing but trouble in the past. In my experience, there are only few situations where --user installs are justified, and usually a virtual environment is the better solution.

@drammock It appears to me pip is trying to install from source, and not the binary wheel. This has got to fail without the headers present.

Best wishes,
Richard

1 Like

ah, good catch. I noticed it was installing from an archive but for some reason that didn’t click for me. In that case the --only-binary flag might help.

2 Likes

hi guys,

I solved the problem by reinstalling the latest version of anaconda 3. I think this error may be caused by some old-version or corrupted packages. Thanks!

1 Like