2

First of all, I am new to python and rasterio. I am trying to open a simple raster with 5 bands using the rasterio module in python. This is what I am trying to achieve:

import rasterio

with rasterio.open('/Users/martinsiklar/Downloads/LC81330242015176LGN00/baikal_subset.tif') as src:
    print(src.width, src.height)
    print(src.count)
    print(src.indexes)
    print(src.dtypes)
    print(src.crs)
    print(src.transform)

Unfortunately I am getting the following Error and I can't really figure out what's wrong. Google didn't help either:

Traceback (most recent call last): File "/Users/martinsiklar/Martin/Python/arcpy/arcpy101", line 3, in with rasterio.open('/Users/martinsiklar/Downloads/LC81330242015176LGN00/baikal_subset.tif') as src: File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/rasterio/init.py", line 105, in open from rasterio._io import RasterReader File "init.pxd", line 155, in init rasterio._io (rasterio/_io.c:49668)

ValueError: numpy.dtype has the wrong size, try recompiling

Process finished with exit code 1

When I take a look into my modules, rasterio seems to be installed properly (as far as I can tell.) The path of the .tif is also correct. I have numpy 1.8 installed.

  • Looks like you have an old version of numpy. What does python -c "import numpy; print numpy.__version__" print out? – user2856 Feb 4 '16 at 0:55
  • it prints out 1.8.0 – maRtin Feb 4 '16 at 1:21
  • 1
    You may need to upgrade numpy (test this out in a virtualenv, don't break your system numpy) as the numpy ABI is not forward compatible. Packages compiled against numpy 1.9 (for example) will not work with numpy 1.8 or lower. It is backwards compatible, so packages compiled against numpy 1.7 (for example) will work with numpy 1.8 or higher. I don't use OSX, but have run into this in Windows where RasterIO wouldn't run against my numpy 1.7.1, but required numpy 1.9. – user2856 Feb 4 '16 at 1:39
  • According to the rasterio requirements it should work with numpy >= 1.8.0. What version of rasterio and GDAL are you using? – Kersten Feb 4 '16 at 9:46
  • 3
    @Kersten yes rasterio will work with numpy >=1.8.0 if the rasterio binaries (pyd) are compiled against numpy 1.8.0. If the rasterio binaries were built against numpy 1.9x, they will only work work with numpy >= 1.9. i.e if rasterio is built against numpy 1.8, you can use numpy 1.8, 1.9, 1.10 etc. if rasterio is built against numpy 1.9, you can't use numpy 1.8, only 1.9, 1.10, etc. The error message in the Q is showing an ABI incompatibility – user2856 Feb 5 '16 at 1:19
1

The error message is showing an ABI incompatibility. You need to upgrade numpy (I suggest testing this out in a virtualenv) as the numpy ABI is not forward compatible.

This means binary extension packages (such as rasterio or pandas) that were compiled against a version of numpy (1.9 for example) will not work with an earlier version of numpy (e.g 1.8 or lower), even if they are API compatible with that earlier version.

While rasterio is API compatible with numpy >=1.8, it will only work with numpy 1.8 if the rasterio binaries (pyd) are compiled against numpy 1.8. If the rasterio binaries were built against numpy 1.9x, they will only work with numpy >= 1.9.

i.e if rasterio is built against numpy 1.8, you can use rasterio with numpy 1.8, 1.9, 1.10 etc. However, if rasterio is built against numpy 1.9, you can't use numpy 1.8, only 1.9, 1.10, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.