adematti / pyclass

Other
0 stars 1 forks source link

numpy 2.0 #4

Closed zhaoruiyang98 closed 4 months ago

zhaoruiyang98 commented 4 months ago

Hi!

The pyclass building fails because of the recent numpy 2.0 update (pip will create an isolated virtual environment to build the package, so the latest numpy is always used). A workaround is to specify numpy<2 as the build time dependency in the pyproject.toml file.

A minimum example to reproduce this issue:

conda create -p ./env "python=3.10" "numpy<2" "cython"
conda activate ./env
python -m pip install git+https://github.com/adematti/pyclass

The error message appears like

      [1/1] Cythonizing pyclass/base/binding.pyx
      building 'pyclass.base.binding' extension
      creating build/temp.macosx-11.0-arm64-cpython-310/pyclass
      creating build/temp.macosx-11.0-arm64-cpython-310/pyclass/base
      /opt/homebrew/bin/gcc-14 -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /Users/ruiyang/source/tmp/env/include -arch arm64 -fPIC -O2 -isystem /Users/ruiyang/source/tmp/env/include -arch arm64 -Ibuild/temp.macosx-11.0-arm64-cpython-310/base/external/RecfastCLASS -Ibuild/temp.macosx-11.0-arm64-cpython-310/base/external/HyRec2020 -Ibuild/temp.macosx-11.0-arm64-cpython-310/base/external/heating -Ibuild/temp.macosx-11.0-arm64-cpython-310/base/include -I/Users/ruiyang/source/tmp/env/include/python3.10 -I/private/var/folders/kv/0xt54_y90ps_mz6_k9b20xgc0000gn/T/pip-build-env-gsff01n2/overlay/lib/python3.10/site-packages/numpy/_core/include -c pyclass/base/binding.c -o build/temp.macosx-11.0-arm64-cpython-310/pyclass/base/binding.o
      In file included from /private/var/folders/kv/0xt54_y90ps_mz6_k9b20xgc0000gn/T/pip-build-env-gsff01n2/overlay/lib/python3.10/site-packages/numpy/_core/include/numpy/ndarraytypes.h:1909,
                       from /private/var/folders/kv/0xt54_y90ps_mz6_k9b20xgc0000gn/T/pip-build-env-gsff01n2/overlay/lib/python3.10/site-packages/numpy/_core/include/numpy/ndarrayobject.h:12,
                       from /private/var/folders/kv/0xt54_y90ps_mz6_k9b20xgc0000gn/T/pip-build-env-gsff01n2/overlay/lib/python3.10/site-packages/numpy/_core/include/numpy/arrayobject.h:5,
                       from pyclass/base/binding.c:1260:
      /private/var/folders/kv/0xt54_y90ps_mz6_k9b20xgc0000gn/T/pip-build-env-gsff01n2/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]
         17 | #warning "Using deprecated NumPy API, disable it with " \
            |  ^~~~~~~
      In file included from /private/var/folders/kv/0xt54_y90ps_mz6_k9b20xgc0000gn/T/pip-build-env-gsff01n2/overlay/lib/python3.10/site-packages/numpy/_core/include/numpy/npy_common.h:376,
                       from /private/var/folders/kv/0xt54_y90ps_mz6_k9b20xgc0000gn/T/pip-build-env-gsff01n2/overlay/lib/python3.10/site-packages/numpy/_core/include/numpy/ndarraytypes.h:4:
      build/temp.macosx-11.0-arm64-cpython-310/base/include/quadrature.h:19:10: error: expected identifier or '(' before '__extension__'
         19 |   double I;             /* Estimate of integral */
            |          ^
      build/temp.macosx-11.0-arm64-cpython-310/base/include/arrays.h:465:56: error: expected ')' before '__extension__'
        465 |                                  double * __restrict__ I,
            |                                                        ^
      In file included from build/temp.macosx-11.0-arm64-cpython-310/base/include/class.h:17,
                       from pyclass/base/binding.c:1267:
      build/temp.macosx-11.0-arm64-cpython-310/base/include/arrays.h:466:34: error: expected ';', ',' or ')' before 'ErrorMsg'
        466 |                                  ErrorMsg errmsg);
            |                                  ^~~~~~~~
      build/temp.macosx-11.0-arm64-cpython-310/base/include/arrays.h:472:59: error: expected ')' before '__extension__'
        472 |                                     double * __restrict__ I,
            |                                                           ^
      build/temp.macosx-11.0-arm64-cpython-310/base/include/arrays.h:473:37: error: expected ';', ',' or ')' before 'ErrorMsg'
        473 |                                     ErrorMsg errmsg);
            |                                     ^~~~~~~~
      error: command '/opt/homebrew/bin/gcc-14' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyclass
adematti commented 4 months ago

Hi Ruiyang,

Thanks! Can you try with the last commit b322c901032018536418da537e0ce9c0785cb949?

zhaoruiyang98 commented 4 months ago

Thanks Arnaud, it works now!