Read CDF files in Python

For CDF file read / write, consider pure Python + Numpy cdflib as cdflib is OS-agnostic, easy to install and performant.

SpacePy can read / write Common Data Format “.cdf” files in Python, among other space science tasks. The .cdf file format is totally different from “.nc” NetCDF4 files, which are essentially special HDF5 files. In general if you’re just doing CDF file I/O consider cdflib instead of SpacePy.


Note: The procedure below is for Linux. Most users should instead consider cdflib to read / write CDF files.

Get needed build tools first:

apt install make gcc gfortran


git clone

python spacepy-installer/


Fix Error

spacepy.pycdf.CDFError: NO_SUCH_CDF: The specified CDF does not exist.

add to your Python program before importing SpacePy.pycdf:

import os

os.environ['CDF_LIB'] = '~/cdf/lib'

or wherever you installed CDF to.