1

I am trying to install NetCDF4 on Rp 3B+. This is the command I used:

sudo pip3 install netcdf4

But the error message is:

Collecting netcdf4
  Using cached https://files.pythonhosted.org/packages/64/2e/abc0bce095ab5a3b8374f052ace2509a031fd7633b23917e557487067225/netCDF4-1.5.2.tar.gz
Collecting cftime (from netcdf4)
  Downloading https://www.piwheels.org/simple/cftime/cftime-1.0.3.4-cp35-cp35m-linux_armv7l.whl (903kB)
    100%  911kB 317kB/s 
Requirement already satisfied: numpy>=1.7 in /usr/lib/python3/dist-packages (from netcdf4)
Building wheels for collected packages: netcdf4
  Running setup.py bdist_wheel for netcdf4 ... error
  Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-f62pls0g/netcdf4/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmp01n9p9ispip-wheel- --python-tag cp35:
  reading from setup.cfg...
  using pkg-config ...
  Package netcdf was not found in the pkg-config search path.
  Perhaps you should add the directory containing netcdf.pc
  to the PKG_CONFIG_PATH environment variable
  No package 'netcdf' found
  unable to detect netcdf library version
  using Cython to compile netCDF4.pyx...
  netcdf lib does not have group rename capability
  netcdf lib does not have nc_inq_path function
  netcdf lib does not have nc_inq_format_extended function
  netcdf lib does not have nc_open_mem function
  netcdf lib does not have nc_create_mem function
  netcdf lib does not have cdf-5 format capability
  netcdf lib does not have netcdf4 parallel functions
  netcdf lib does not have pnetcdf parallel functions
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-armv7l-3.5
  creating build/lib.linux-armv7l-3.5/netCDF4
  copying netCDF4/__init__.py -> build/lib.linux-armv7l-3.5/netCDF4
  copying netCDF4/utils.py -> build/lib.linux-armv7l-3.5/netCDF4
  running build_ext
  cythoning netCDF4/_netCDF4.pyx to netCDF4/_netCDF4.c
  /tmp/pip-build-f62pls0g/netcdf4/.eggs/Cython-0.29.13-py3.5-linux-armv7l.egg/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /tmp/pip-build-f62pls0g/netcdf4/netCDF4/_netCDF4.pyx
    tree = Parsing.p_module(s, pxd, full_module_name)
  building 'netCDF4._netCDF4' extension
  creating build/temp.linux-armv7l-3.5
  creating build/temp.linux-armv7l-3.5/netCDF4
  arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-6waWnr/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/hdf5/serial -I/usr/include/hdf5/serial -I/usr/lib/python3/dist-packages/numpy/core/include -Iinclude -I/usr/include/python3.5m -c netCDF4/_netCDF4.c -o build/temp.linux-armv7l-3.5/netCDF4/_netCDF4.o
  netCDF4/_netCDF4.c:601:20: fatal error: netcdf.h: file or directory does not exist
   #include "netcdf.h"
                      ^
  compilation terminated.
  error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for netcdf4
  Running setup.py clean for netcdf4
Failed to build netcdf4
Installing collected packages: cftime, netcdf4
  Running setup.py install for netcdf4 ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-f62pls0g/netcdf4/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-ckh54a_u-record/install-record.txt --single-version-externally-managed --compile:
    reading from setup.cfg...
    using pkg-config ...
    Package netcdf was not found in the pkg-config search path.
    Perhaps you should add the directory containing netcdf.pc
    to the PKG_CONFIG_PATH environment variable
    No package 'netcdf' found
    unable to detect netcdf library version
    using Cython to compile netCDF4.pyx...
    netcdf lib does not have group rename capability
    netcdf lib does not have nc_inq_path function
    netcdf lib does not have nc_inq_format_extended function
    netcdf lib does not have nc_open_mem function
    netcdf lib does not have nc_create_mem function
    netcdf lib does not have cdf-5 format capability
    netcdf lib does not have netcdf4 parallel functions
    netcdf lib does not have pnetcdf parallel functions
    running install
    running build
    running build_py
    running build_ext
    cythoning netCDF4/_netCDF4.pyx to netCDF4/_netCDF4.c
    /tmp/pip-build-f62pls0g/netcdf4/.eggs/Cython-0.29.13-py3.5-linux-armv7l.egg/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /tmp/pip-build-f62pls0g/netcdf4/netCDF4/_netCDF4.pyx
      tree = Parsing.p_module(s, pxd, full_module_name)
    building 'netCDF4._netCDF4' extension
    creating build/temp.linux-armv7l-3.5
    creating build/temp.linux-armv7l-3.5/netCDF4
    arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-6waWnr/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/hdf5/serial -I/usr/include/hdf5/serial -I/usr/lib/python3/dist-packages/numpy/core/include -Iinclude -I/usr/include/python3.5m -c netCDF4/_netCDF4.c -o build/temp.linux-armv7l-3.5/netCDF4/_netCDF4.o
    netCDF4/_netCDF4.c:601:20: fatal error: netcdf.h: file or directory does not exist
     #include "netcdf.h"
                        ^
    compilation terminated.
    error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-f62pls0g/netcdf4/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-ckh54a_u-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-f62pls0g/netcdf4/

I'm a bit lost in here. Where should I start unwinding this? Any suggestions are welcome.

2
  • Does it work? I don't see an error, just informational messages.
    – joan
    Commented Oct 20, 2019 at 19:05
  • Hum, good question. I did not even try to use it because there are so many "Failed" messages. Now it's too late to try did it work because in my answer below I got it working. But thanks for very fast comment. Commented Oct 20, 2019 at 19:22

1 Answer 1

1

Ok I figured it out. I already had installed h5py by the following lines as in this link:

sudo apt-get install libhdf5-dev
sudo apt-get install libhdf5-serial-dev
sudo python3 -m pip install h5py

And after those following this link

sudo apt-get install netcdf-bin libnetcdf-dev
sudo python3 -m pip install netcdf4

And now import netCDF4 works.

By the way, is there any difference between using python3 -m pip install <package> and using pip3 install <package> ? I have always thought they are synonyms, but would like to know for sure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.