Topics

`import rasterio` error on Win7 and Mac: ValueError: numpy.dtype has the wrong size, try recompiling

nurbachris@...
 

I am having the same problem on Windows 7 and Mac OS X High Sierra:

1) Windows 7 (64 bits)

Using python 2.7 (32 bits).

I have installed GDAL Core and its Python bindings using the executables here (resp. gdal-202-1500-core.msi and GDAL-2.2.3.win32-py2.7.msi). This worked well and I could successfully use gdal in python scripts.

Then I tried to install rasterio using rasterio‑1.0.3‑cp27‑cp27m‑win32.whl:
py -2.7 -m pip install rasterio‑1.0.3‑cp27‑cp27m‑win32.whl

This went through successfully.

However when starting python and invoking import rasterio I get the following error message:

Traceback (most recent call last):
  File "test1.py", line 1, in <module>
    import rasterio
  File "C:\Python27\lib\site-packages\rasterio\__init__.py", line 31, in <module>
    from rasterio._base import gdal_version
  File "rasterio\_base.pyx", line 1, in init rasterio._base
  File "__init__.pxd", line 164, in init rasterio._shim
ValueError: numpy.dtype has the wrong size, try recompiling. Expected 52, got 56

2) Mac OS X High Sierra (10.13.6)

Interestingly, I am having exactly the same error on Mac OS X High Sierra after installing GDAL Complete 2.1 from here, and rasterio using:
pip2.7 install rasterio.

The installation steps are successful, but I get the same error as above when executing import rasterio in python 2.7:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/rasterio/__init__.py", line 23, in <module>
    from rasterio._base import gdal_version
  File "rasterio/_base.pyx", line 1, in init rasterio._base
  File "__init__.pxd", line 164, in init rasterio._shim
ValueError: numpy.dtype has the wrong size, try recompiling. Expected 88, got 96

I have read posts advising to upgrade numpy, however it is installed as distutils project (on both systems) and therefore I cannot upgrade with pip. So I am not sure what is the best way forward.

Any help would be greatly appreciated.

Sean Gillies
 

I am sorry, but upgrading numpy is the only way forward. If you don't want to overwrite your existing numpy installation, you have several  options. I believe the following two are the best. Other group members may have different experiences.

1. Download python 3.6 or 3.7 from python.org and install it. Now you have a brand new (and better) version of python into which you can install packages. On your Mac, `python3 -m pip install rasterio` will cause numpy to be fetched and installed, too. On your Windows computer, you will need to get numpy separately from https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy and install it.

2. Install Miniconda (3.6 again) https://conda.io/miniconda.html and get Rasterio from conda-forge: `conda install -c conda-forge rasterio`.

Good luck!

On Tue, Aug 7, 2018 at 8:33 AM <nurbachris@...> wrote:

I am having the same problem on Windows 7 and Mac OS X High Sierra:

1) Windows 7 (64 bits)

Using python 2.7 (32 bits).

I have installed GDAL Core and its Python bindings using the executables here (resp. gdal-202-1500-core.msi and GDAL-2.2.3.win32-py2.7.msi). This worked well and I could successfully use gdal in python scripts.

Then I tried to install rasterio using rasterio‑1.0.3‑cp27‑cp27m‑win32.whl:
py -2.7 -m pip install rasterio‑1.0.3‑cp27‑cp27m‑win32.whl

This went through successfully.

However when starting python and invoking import rasterio I get the following error message:

Traceback (most recent call last):
  File "test1.py", line 1, in <module>
    import rasterio
  File "C:\Python27\lib\site-packages\rasterio\__init__.py", line 31, in <module>
    from rasterio._base import gdal_version
  File "rasterio\_base.pyx", line 1, in init rasterio._base
  File "__init__.pxd", line 164, in init rasterio._shim
ValueError: numpy.dtype has the wrong size, try recompiling. Expected 52, got 56

2) Mac OS X High Sierra (10.13.6)

Interestingly, I am having exactly the same error on Mac OS X High Sierra after installing GDAL Complete 2.1 from here, and rasterio using:
pip2.7 install rasterio.

The installation steps are successful, but I get the same error as above when executing import rasterio in python 2.7:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/rasterio/__init__.py", line 23, in <module>
    from rasterio._base import gdal_version
  File "rasterio/_base.pyx", line 1, in init rasterio._base
  File "__init__.pxd", line 164, in init rasterio._shim
ValueError: numpy.dtype has the wrong size, try recompiling. Expected 88, got 96

I have read posts advising to upgrade numpy, however it is installed as distutils project (on both systems) and therefore I cannot upgrade with pip. So I am not sure what is the best way forward.

Any help would be greatly appreciated.



--
Sean Gillies