freesurfer/surfa

Installation issues with numpy 2.0

rkm opened this issue · 2 comments

rkm commented

Hi 👋 I encountered the following issue when trying to install surfa on ubuntu 22.04.

A minimal Dockerfile produces the output below:

FROM ubuntu:22.04
RUN apt -y update && DEBIAN_FRONTEND=noninteractive apt -y install build-essential python3-dev python3-venv
RUN python3 -mvenv /venv && /venv/bin/pip install surfa
...
33.16       x86_64-linux-gnu-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/tmp/pip-build-env-kxps_n1p/overlay/lib/python3.10/site-packages/numpy/_core/include -I/venv/include -I/usr/include/python3.10 -c surfa/image/interp.c -o build/temp.linux-x86_64-cpython-310/surfa/image/interp.o -O3 -std=c99
33.16       In file included from /tmp/pip-build-env-kxps_n1p/overlay/lib/python3.10/site-packages/numpy/_core/include/numpy/ndarraytypes.h:1909,
33.16                        from /tmp/pip-build-env-kxps_n1p/overlay/lib/python3.10/site-packages/numpy/_core/include/numpy/ndarrayobject.h:12,
33.16                        from /tmp/pip-build-env-kxps_n1p/overlay/lib/python3.10/site-packages/numpy/_core/include/numpy/arrayobject.h:5,
33.16                        from surfa/image/interp.c:763:
33.16       /tmp/pip-build-env-kxps_n1p/overlay/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
33.16          17 | #warning "Using deprecated NumPy API, disable it with " \
33.16             |  ^~~~~~~
33.16       In file included from /usr/include/python3.10/Python.h:74,
33.16                        from surfa/image/interp.c:23:
33.16       surfa/image/interp.c: In function ‘__pyx_f_5numpy_PyDataType_SHAPE’:
33.16       surfa/image/interp.c:54245:39: error: ‘PyArray_Descr’ {aka ‘struct _PyArray_Descr’} has no member named ‘subarray’
33.16       54245 |     __Pyx_INCREF(((PyObject*)__pyx_v_d->subarray->shape));
33.16             |                                       ^~
33.16       /usr/include/python3.10/object.h:112:41: note: in definition of macro ‘_PyObject_CAST’
33.16         112 | #define _PyObject_CAST(op) ((PyObject*)(op))
33.16             |                                         ^~
33.16       surfa/image/interp.c:1540:27: note: in expansion of macro ‘Py_INCREF’
33.16        1540 |   #define __Pyx_INCREF(r) Py_INCREF(r)
33.16             |                           ^~~~~~~~~
33.16       surfa/image/interp.c:54245:5: note: in expansion of macro ‘__Pyx_INCREF’
33.16       54245 |     __Pyx_INCREF(((PyObject*)__pyx_v_d->subarray->shape));
33.16             |     ^~~~~~~~~~~~
33.16       surfa/image/interp.c:54246:36: error: ‘PyArray_Descr’ {aka ‘struct _PyArray_Descr’} has no member named ‘subarray’
33.16       54246 |     __pyx_r = ((PyObject*)__pyx_v_d->subarray->shape);
33.16             |                                    ^~
33.16       error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
33.16       [end of output]
33.16
33.16   note: This error originates from a subprocess, and is likely not a problem with pip.
33.16   ERROR: Failed building wheel for surfa
33.16 Failed to build surfa
33.16 ERROR: Could not build wheels for surfa, which is required to install pyproject.toml-based projects

The following Dockerfile builds successfully:

FROM ubuntu:22.04
RUN apt -y update && DEBIAN_FRONTEND=noninteractive apt -y install build-essential python3-dev python3-venv
RUN python3 -mvenv /venv && /venv/bin/pip install wheel 'numpy<2.0' && /venv/bin/pip install --no-build-isolation surfa
rkm commented

Pinning numpy<2.0 here should fix this:

requires = ['setuptools', 'wheel', 'Cython', 'numpy']

Thanks for pointing this out. Pinned Numpy for now.
You can also use python <=3.9 to resolve this without pinning Numpy.