5

I would like to install netcdf4-python to my Ubuntu14.04. The libhdf5-dev_1.8.11_5ubuntu7_amd64.deb and libnetcdf-4.1.3-7ubuntu2_amd64.deb are installed. I downloaded netcdf4-1.1.8.tar.gz from https://pypi.python.org/pypi/netCDF4#downloads I tried configure it by

./configure --enable-netcdf-4 –with-hdf5=/usr/include/ --enable-share –prefix=/usr

but I got the following message:

bash: ./configure: No such file or directory

I do not know how I can install netcdf4-python. I would appreciated if someone helped me.

Beata
  • 335
  • 2
  • 10
  • 21

5 Answers5

4

I would strongly recommend using the Anaconda Python distribution. The full Anaconda distribution includes netcdf4 and the required libraries.

jhamman
  • 5,867
  • 19
  • 39
2

The instructions for Ubuntu are here which are basically:

HDF5

Download the current HDF5 source release. Unpack, go into the directory and execute:

./configure --prefix=/usr/local --enable-shared --enable-hl
make 
sudo make install

To speed things up, compile on more than one processor using

make -j n 

where n is the number of processes to be launched.

netCDF4 e Download the current netCDF4 source release. Unpack, go into the directory and execute:

LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/include ./configure --enable-netcdf-4 --enable-dap --enable-shared --prefix=/usr/local
make 
make install

Installing netcdf4-python When both HDF5 and netCDF4 are in /usr/local, make sure the linker will be able to find those libraries by executing

sudo ldconfig

then installing netcdf4-python is just a matter of doing

python setup.py install

Make sure you actually untar the files and cd to the correct directories.

Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
2

You can also use an alternative wrapper for the netCDF4, like the netcdf library (it compile the hdf5 and netCDF4 libraries from sourcecode, automatically), using:

pip install netcdf
ecolell
  • 125
  • 3
  • 9
  • 1
    shouldn't that be `pip install netcdf4` ? – Alf Apr 11 '17 at 08:55
  • No, thats another library... the one I mention compile the netCDF4 and HDF5 libraries from sources. – ecolell Apr 11 '17 at 13:21
  • 1
    for me `pip install netcdf4` as suggested by @Alf worked, while the solution of @ecolell 's suggestion errored out with `ValueError: did not find HDF5` headers` in Ubuntu18.04 – Wolke-Wanderer Sep 17 '20 at 18:39
1

The netCDF4 python module documentation can be found here. Check out the "Install" section; it'll have what you're looking for. But, if you satisfy all of the pre-requisites you can simply do the following:

python setup.py build && python setup.py install
awmo
  • 329
  • 1
  • 2
  • 1
    I could to solve the netcdf4 installation but I do not know where I have to write `python setup.py install`? When I type it I get the following error: `python: can't open file 'setup.py': [Errno 2] No such file or directory` I tried run it in `/usr/lib/python2.7/dist-packages/numpy$` but `This is the wrong setup.py file to run` – Beata Jul 20 '15 at 07:44
1

After much struggle with the installation and getting errors similar to the ones mentioned in this post, I ended up installing it as follows:

1) Installed HDF5

./configure --prefix=/usr/local --enable-shared --enable-hl
make 
sudo make install

2) Installed netcdf4

 sudo pip install netcdf4

I guess the pip command would have installed the pre-requisite HDF5 as well even if I didn't do step (1). Btw, I have pip version 8.0.2 and python 2.7

Zahra
  • 6,798
  • 9
  • 51
  • 76