lesgourg / class_public

Public repository of the Cosmic Linear Anisotropy Solving System (master for the most recent version of the standard code; GW_CLASS to include Cosmic Gravitational Wave Background anisotropies; classnet branch for acceleration with neutral networks; ExoCLASS branch for exotic energy injection; class_matter branch for FFTlog)
223 stars 291 forks source link

Installation error using python3.12 #584

Open deyanmihaylov opened 1 month ago

deyanmihaylov commented 1 month ago

When I try to install classy using

pip install classy

I get the following error

     clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
      clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
      clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
      clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
      clangclang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
      : warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
      clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
      ar rv  libclass.a build/growTable.o build/dei_rkck.o build/sparse.o build/evolver_rkck.o build/evolver_ndf15.o build/arrays.opp build/parser.o build/quadrature.o build/hyperspherical.opp build/common.o build/trigonometric_integrals.o build/input.o build/background.o build/thermodynamics.o build/perturbations.opp build/primordial.opp build/fourier.o build/transfer.opp build/harmonic.opp build/lensing.opp build/distortions.o build/wrap_recfast.o build/injection.o build/noninjection.o build/hyrectools.o build/helium.o build/hydrogen.o build/history.o build/wrap_hyrec.o build/energy_injection.o
      ar: creating archive libclass.a
      a - build/growTable.o
      a - build/dei_rkck.o
      a - build/sparse.o
      a - build/evolver_rkck.o
      a - build/evolver_ndf15.o
      a - build/arrays.opp
      a - build/parser.o
      a - build/quadrature.o
      a - build/hyperspherical.opp
      a - build/common.o
      a - build/trigonometric_integrals.o
      a - build/input.o
      a - build/background.o
      a - build/thermodynamics.o
      a - build/perturbations.opp
      a - build/primordial.opp
      a - build/fourier.o
      a - build/transfer.opp
      a - build/harmonic.opp
      a - build/lensing.opp
      a - build/distortions.o
      a - build/wrap_recfast.o
      a - build/injection.o
      a - build/noninjection.o
      a - build/hyrectools.o
      a - build/helium.o
      a - build/hydrogen.o
      a - build/history.o
      a - build/wrap_hyrec.o
      a - build/energy_injection.o

      Error compiling Cython file:
      ------------------------------------------------------------
      ...
              return d.items()
          else:
              return d.viewitems()

      ctypedef np.float_t DTYPE_t
      ctypedef np.int_t DTYPE_i
               ^
      ------------------------------------------------------------

      class_public/python/classy.pyx:35:9: 'int_t' is not a type identifier
      warning: class_public/python/classy.pyx:363:76: local variable 'errmsg' referenced before assignment
      warning: class_public/python/classy.pyx:364:39: local variable 'errmsg' referenced before assignment
      Compiling class_public/python/classy.pyx because it changed.
      [1/1] Cythonizing class_public/python/classy.pyx
      Traceback (most recent call last):
        File "/Users/deyanmihaylov/Documents/Work/pyenvs/python312/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/Users/deyanmihaylov/Documents/Work/pyenvs/python312/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/Users/deyanmihaylov/Documents/Work/pyenvs/python312/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel
          return _build_backend().build_wheel(wheel_directory, config_settings,
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 415, in build_wheel
          return self._build_with_temp_dir(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 397, in _build_with_temp_dir
          self.run_setup()
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 313, in run_setup
          exec(code, locals())
        File "<string>", line 83, in <module>
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/__init__.py", line 108, in setup
          return distutils.core.setup(**attrs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 184, in setup
          return run_commands(dist)
                 ^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 200, in run_commands
          dist.run_commands()
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 970, in run_commands
          self.run_command(cmd)
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/dist.py", line 945, in run_command
          super().run_command(command)
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 989, in run_command
          cmd_obj.run()
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/command/bdist_wheel.py", line 373, in run
          self.run_command("build")
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 316, in run_command
          self.distribution.run_command(command)
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/dist.py", line 945, in run_command
          super().run_command(command)
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 989, in run_command
          cmd_obj.run()
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/_distutils/command/build.py", line 135, in run
          self.run_command(cmd_name)
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 316, in run_command
          self.distribution.run_command(command)
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/dist.py", line 945, in run_command
          super().run_command(command)
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 989, in run_command
          cmd_obj.run()
        File "<string>", line 77, in run
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 359, in run
          self.build_extensions()
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 479, in build_extensions
          self._build_extensions_serial()
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/setuptools/_distutils/command/build_ext.py", line 505, in _build_extensions_serial
          self.build_extension(ext)
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/Cython/Distutils/build_ext.py", line 130, in build_extension
          new_ext = cythonize(
                    ^^^^^^^^^^
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
          cythonize_one(*args)
        File "/private/var/folders/_9/tgq57xfn3wlddld6773mdtq00000gn/T/pip-build-env-_iamnsuw/overlay/lib/python3.12/site-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
          raise CompileError(None, pyx_file)
      Cython.Compiler.Errors.CompileError: class_public/python/classy.pyx
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for classy
Failed to build classy
ERROR: Could not build wheels for classy, which is required to install pyproject.toml-based projects
deyanmihaylov commented 1 month ago

Here is the entire traceback which could not be pasted in the issue: https://pastebin.com/ZFJmv4H7

cmbant commented 1 month ago

Cobaya tests fail due to the same issue when compiling with py12 and numpy 2. I think numpy 2 removed "int_t". Log: https://app.travis-ci.com/github/CobayaSampler/cobaya/builds/271808045

deyanmihaylov commented 1 month ago

Is there any plan to provide a fix? I don't know if you can do it on your end, or cobaya maintainers have to issue a new release.

cmbant commented 1 month ago

This is a CLASS problem, nothing to do with Cobaya. For local builds you can try changing the int_t declarations yourself or you can install an earlier numpy version.

tanveerkarim commented 1 month ago

I am having the same issue with installing classy. My Python version is 3.10.11.

stanaka2 commented 2 weeks ago

Since numpy2, the way to specify the type of np.int_t seems to have become strict. Until it is fixed on the CLASS side, you can install it by downloading and editing the file as follows.

pip cache purge
pip download --no-deps classy
tar -zxvf classy-3.2.3.2.tar.gz
cd classy-3.2.3.2/
sed -i 's/np\.int_t/np.int64_t/g' class_public/python/classy.pyx
pip install .

It can install and import, but I don't know if numpy2 will cause any problems. As long as I am using it, there is no problem.