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)
235 stars 291 forks source link

Installation error using python3.12 #584

Open deyanmihaylov opened 3 months ago

deyanmihaylov commented 3 months 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 3 months ago

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

cmbant commented 3 months 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 3 months 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 3 months 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 3 months ago

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

stanaka2 commented 3 months 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.

lesgourg commented 2 weeks ago

Hi! I believe that this was fixed by the release of CLASS v3.2.4 on the 30.09.2024 (and it should still be OK with the current v3.2.5). If you still have similar problems with recent versions, you can open an issue on https://github.com/lesgourg/class_public

nikosarcevic commented 4 days 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.

Hi all

I think it would be a good idea to add this to the package page as a temporary solution as more of us are facing the same issue.

many thanks!

nikosarcevic commented 4 days 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.

Hi all

I think it would be a good idea to add this to the package page as a temporary solution as more of us are facing the same issue.

many thanks!

also, this is the macOS version of the solution


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 .
nikosarcevic commented 4 days ago

forgot to add in case you need this info:

(ccl3) niko @ MacBook-Pro-83.local : ~/Documents/Research/forecasting_validation% python3 check_version.py
Python version: 3.12.7
NumPy version: 1.26.4
Operating System: macOS 15.1.1
Processor: i386
Memory: 8.00 GB

So, to conclude, I had the Error Installing CLASSy Due to Cython Compilation Issue on this setup.

lesgourg commented 4 days ago

Dear @nikosarcevic , in your example I see that you are using class v3.2.3. I would have thought that this problem was fixed already in v3.2.4 on the 30.09.2024 (and we are now at v3.2.5 since the 4.10.2024). Can you check whether you meet this kind of numpy issues with v3.2.4 or 3.2.5? If yes we should really do something more. You can either clone the new versions, or just merge them in your class if you have done your own modifications.

nikosarcevic commented 4 days ago

Hi, @lesgourg hope you are doign well!

Let me see if I can do this quickly as I have telecons soon. I believe I am calling class via ccl but need to check what is actually going on. Will report back!

nikosarcevic commented 4 days ago

Hi again, @lesgourg

It seems that, if my understanding is correct, the issue was resolved in CLASS version 3.2.5, as pulling this version from GitHub, building it manually, and installing the Python wrapper (classy) worked for me. The NumPy compatibility issue (np.int_t) no longer occurs with this version.

however, I noticed that classy version 3.2.5 is not available on PyPI. Users relying on pip install classy might still face the same problem unless they manually pull and build from GitHub. Perhaps publishing the latest version to PyPI could help prevent this confusion for others. (or adding the solutions above as a temporary fix until 3.2.5 is avail)

lesgourg commented 4 days ago

Many thanks @nikosarcevic , I had not realised that 3.2.5 was not available on PyPI, we will fix this!

nikosarcevic commented 4 days ago

@lesgourg Brilliant! Many, many thanks!