NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: [python-users] netCDF4/h5Py in the same Python 3 script

  • To: Aaron Funk <afunk@xxxxxxxx>
  • Subject: Re: [python-users] netCDF4/h5Py in the same Python 3 script
  • From: Ryan May <rmay@xxxxxxxx>
  • Date: Fri, 24 Jan 2020 13:36:44 -0700
Hi,

I'm not aware of any reason those two modules should interfere--provided
they're using the same libhdf5. Can you provide the full traceback and text
of the error? Otherwise we're just shooting in the dark here.

I can say that the following code works without error for me on macOS 10.15
and Python 3.8, all from conda-forge:

from netCDF4 import Dataset
import h5py
import numpy as np

nc = Dataset('test.nc', 'w')
nc.createDimension('x', 10)
nc.createDimension('y', 20)
var = nc.createVariable('test', np.float64, ('x', 'y'))
var[:] = np.arange(200.).reshape(10, 20)
nc.close()

Does this code fail for you?

Ryan

On Wed, Jan 22, 2020 at 10:45 AM Aaron Funk <afunk@xxxxxxxx> wrote:

> Hi all,
>
> I'm new to Python and reaching out here for information on an issue I ran
> into. My issue is that I'm unable to close a netCDF4 object and write a
> file to disk without error if I import h5py and netcdf4 in the same script.
> If I remove the "import h5py" line, the script works fine.
>
> Is this a known/common issue? Is there a way in which I can use both h5py
> and netcdf4 modules in the same Python script without generating these
> types of errors? What's the best workaround for this?
>
> I'm not providing an example script here, but some environment details are
> below. I can provide other info as needed.
>
> Environment:
> CentOS 7
> Python 3.6
> pip virtual environment with h5py and netcdf4 and dependencies installed.
> HDF5 and netCDF-4 C compiled from scratch.
>
> Thanks,
>
> Aaron Funk
> _______________________________________________
> NOTE: All exchanges posted to Unidata maintained email lists are
> recorded in the Unidata inquiry tracking system and made publicly
> available through the web.  Users who post to any of the lists we
> maintain are reminded to remove any personal information that they
> do not want to be made public.
>
>
> python-users mailing list
> python-users@xxxxxxxxxxxxxxxx
> For list information, to unsubscribe, or change your membership options,
> visit: https://www.unidata.ucar.edu/mailing_lists/
>


-- 
Ryan May, Ph.D.
Software Engineer
UCAR/Unidata
Boulder, CO
  • 2020 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the python-users archives: