If the order of the imports matter, then that is almost certainly a library
conflict issue. I encountered a similar problem years ago with the order of
the imports of basemap and osgeo.
What would be good to know is if h5py and netCDF4, when they were installed
via pip, were installed as pre-built, or built from source by pip. I bet
you the problem lies there because the python packages may be loading
different binaries than you think they are loading.
On Fri, Jan 24, 2020 at 4:15 PM Aaron Funk <afunk@xxxxxxxx> wrote:
> Hi Ryan,
> I'm quite new to Python so I may not provide exactly what you asked for
> just due to my own ignorance. If you need more traceback info, please let
> me know.
> What I found is that I can run your example script without error. However,
> if I simply change the order of the import statements and place h5py before
> netCDF4, I get an error similar to what I was seeing in my own code. Here's
> the traceback info printed to the screen:
> Traceback (most recent call last):
> File "ucar_test.py", line 12, in <module>
> var[:] = np.arange(200.).reshape(10, 20)
> File "netCDF4/_netCDF4.pyx", line 4950, in
> File "netCDF4/_netCDF4.pyx", line 5229, in
> File "netCDF4/_netCDF4.pyx", line 1887, in
> RuntimeError: NetCDF: HDF error
> I'll try to be more specific than before about my own environment...
> CentOS 7
> Pip virtual environment using Python 3.6.4
> Installed h5py (2.10.0) and netCDF4 (1.5.3) using pip
> I compiled the HDF5 (1.10.6) and netCDF4 (4.7.3) libraries from source and
> are installed locally
> and pointed to using the LD_LIBRARY_PATH environment var. netCDF4 was
> compiled pointing to the HDF5 lib I compiled so I believe everything's
> using the same libhdf5.
> On Fri, Jan 24, 2020 at 2:37 PM Ryan May <rmay@xxxxxxxx> wrote:
>> 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
>> nc.createDimension('x', 10)
>> nc.createDimension('y', 20)
>> var = nc.createVariable('test', np.float64, ('x', 'y'))
>> var[:] = np.arange(200.).reshape(10, 20)
>> Does this code fail for you?
>> 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.
>>> CentOS 7
>>> Python 3.6
>>> pip virtual environment with h5py and netcdf4 and
>>> dependencies installed.
>>> HDF5 and netCDF-4 C compiled from scratch.
>>> 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
>>> For list information, to unsubscribe, or change your membership options,
>>> visit: https://www.unidata.ucar.edu/mailing_lists/
>> Ryan May, Ph.D.
>> Software Engineer
>> Boulder, CO
> 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
> For list information, to unsubscribe, or change your membership options,
> visit: https://www.unidata.ucar.edu/mailing_lists/