-
Notifications
You must be signed in to change notification settings - Fork 2.4k
GDAL should have dependency on py-numpy when building with +python #8469
Description
Since the changes to the gdal/package.py on May 26, it builds without the capacity to use numpy arrays in the Python bindings.
In the previous version of the gdal/package.py, it had an explicit build and run dependency on py-numpy, but this is now missing. I suspect that it is necessary.
When I add this back in to gdal/package.py as follows, the problem disappears again. (I added the when='+python', which was not in the original)
depends_on('py-numpy', type=('build', 'run'), when='+python')
I suspect that the lack of 'build' dependency is the main flaw. When GDAL is building, it thinks that numpy is not available, and quietly builds the numpy-free parts of the Python bindings.
Expected Result
GDAL Python bindings should be able to use ReadAsArray() to read raster data into a numpy array.
Actual Result
If built with +python, the resulting python bindings produce an error when reading raster data with ReadAsArray().
This is true even if py-numpy is already installed and available in the environment.
Steps to reproduce the issue
$ spack install gdal+python
$ module load gdal-2.3.0-gcc-6-python2-rsfov4z
$ python
>>> from osgeo import gdal
>>> ds = gdal.Open('image.tif')
>>> b = ds.GetRasterBand(1)
>>> a = b.ReadAsArray()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/scratch/rsc7/floodn/spackInstall2/opt/spack/linux-sles12-x86_64/gcc-6/gdal-2.3.0-mqthuimmblu3uqd2uicgoh7bwjyxq3xf/lib/python2.7/site-packages/osgeo/gdal.py", line 2605, in ReadAsArray
import gdalnumeric
File "/scratch/rsc7/floodn/spackInstall2/opt/spack/linux-sles12-x86_64/gcc-6/gdal-2.3.0-mqthuimmblu3uqd2uicgoh7bwjyxq3xf/lib/python2.7/site-packages/osgeo/gdalnumeric.py", line 1, in <module>
from osgeo.gdal_array import *
File "/scratch/rsc7/floodn/spackInstall2/opt/spack/linux-sles12-x86_64/gcc-6/gdal-2.3.0-mqthuimmblu3uqd2uicgoh7bwjyxq3xf/lib/python2.7/site-packages/osgeo/gdal_array.py", line 28, in <module>
_gdal_array = swig_import_helper()
File "/scratch/rsc7/floodn/spackInstall2/opt/spack/linux-sles12-x86_64/gcc-6/gdal-2.3.0-mqthuimmblu3uqd2uicgoh7bwjyxq3xf/lib/python2.7/site-packages/osgeo/gdal_array.py", line 20, in swig_import_helper
import _gdal_array
ImportError: No module named _gdal_arrayInformation on your system
Running on linux-sles12-x86_64, with OS-installed gcc-6.