rasterio / rasterio-wheels

MIT License
11 stars 16 forks source link

Importing rasterio causes a HDF error with netCDF4 #12

Closed sgillies closed 5 years ago

sgillies commented 5 years ago

https://github.com/mapbox/rasterio/issues/1574 by @ererkka copied to this repo.

Expected behavior and actual behavior.

Expected that importing rasterio has no effect on other libraries. Creating a netCDF file using netCDF4 library fails when rasterio is imported first.

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    print(ds)
  File "netCDF4/_netCDF4.pyx", line 2168, in netCDF4._netCDF4.Dataset.__exit__
  File "netCDF4/_netCDF4.pyx", line 2276, in netCDF4._netCDF4.Dataset.close
  File "netCDF4/_netCDF4.pyx", line 2260, in netCDF4._netCDF4.Dataset._close
  File "netCDF4/_netCDF4.pyx", line 1754, in netCDF4._netCDF4._ensure_nc_success
RuntimeError: NetCDF: HDF error

Steps to reproduce the problem.

$ mktmpenv
$ pip install rasterio netCDF4
$ python test.py

test.py

import rasterio
import netCDF4

with netCDF4.Dataset('test.nc', mode='w') as ds:
    ds.createDimension('x')
    ds.createVariable('foo', float, dimensions=('x'))
    print(ds)

Commenting out import rasterio or importing it after netCDF4 removes the error.

Operating system

CentOS release 6.10 (Final)

Rasterio version

Python 3.5.3, pip 18.1

From pip freeze

affine==2.2.1
attrs==18.2.0
cftime==1.0.3.4
Click==7.0
click-plugins==1.0.4
cligj==0.5.0
netCDF4==1.4.2
numpy==1.15.4
pyparsing==2.3.0
rasterio==1.0.11
snuggs==1.4.2

Links to other issues

This might be linked to https://github.com/pydata/xarray/issues/2535.

sgillies commented 5 years ago

Right, there's really no way to solve this here. If you have to use both netCDF4 and rasterio in one program, you'd better get them from conda-forge or build them from source.

dbaston commented 5 years ago

Seems like the same conflict is present with fiona too.