Skip to content

numpy 2.0 errors #250

@tvwenger

Description

@tvwenger

Something broke with the numpy 2.0 update. Installation is fine, but

from turbustat.simulator import make_3dfield

fails with

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "/home/twenger/miniconda3/envs/astro-reu-2024/bin/ipython", line 10, in <module>
    sys.exit(start_ipython())
  File "/home/twenger/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/IPython/__init__.py", line 130, in start_ipython
    return launch_new_instance(argv=argv, **kwargs)
  File "/home/twenger/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/traitlets/config/application.py", line 1075, in launch_instance
    app.start()
  File "/home/twenger/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/IPython/terminal/ipapp.py", line 317, in start
    self.shell.mainloop()
  File "/home/twenger/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/IPython/terminal/interactiveshell.py", line 917, in mainloop
    self.interact()
  File "/home/twenger/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/IPython/terminal/interactiveshell.py", line 910, in interact
    self.run_cell(code, store_history=True)
  File "/home/twenger/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3075, in run_cell
    result = self._run_cell(
  File "/home/twenger/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3130, in _run_cell
    result = runner(coro)
  File "/home/twenger/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/IPython/core/async_helpers.py", line 128, in _pseudo_sync_runner
    coro.send(None)
  File "/home/twenger/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3334, in run_cell_async
    has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
  File "/home/twenger/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3517, in run_ast_nodes
    if await self.run_code(code, result, async_=asy):
  File "/home/twenger/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/IPython/core/interactiveshell.py", line 3577, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-98e5169c3e1e>", line 1, in <module>
    from turbustat.simulator import make_3dfield
  File "/home/twenger/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/turbustat/simulator/__init__.py", line 3, in <module>
    from .make_cube import make_ppv
  File "/home/twenger/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/turbustat/simulator/make_cube.py", line 12, in <module>
    from .spectrum import generate_spectrum
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 from turbustat.simulator import make_3dfield

File ~/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/turbustat/simulator/__init__.py:3
      2 from .gen_field import make_3dfield, make_extended
----> 3 from .make_cube import make_ppv

File ~/miniconda3/envs/astro-reu-2024/lib/python3.12/site-packages/turbustat/simulator/make_cube.py:12
      9 from astropy.io import fits
     11 from ..io.sim_tools import create_cube_header
---> 12 from .spectrum import generate_spectrum
     14 SQRT_2PI = np.sqrt(2 * np.pi)
     15 conv_to_K = 1.823e13 * u.cm**-2 / (u.K * u.cm / u.s)

File turbustat/simulator/spectrum.pyx:2, in init turbustat.simulator.spectrum()

ImportError: numpy.core.multiarray failed to import (auto-generated because you didn't call 'numpy.import_array()' after cimporting numpy; use '<void>numpy._import_array' to disable if you are certain you don't need it).

Downgrading to python 3.9 and numpy<2.0 works.

conda create -n turbustat -c conda-forge "python==3.9" "numpy<2.0"
conda activate turbustat
pip install turbustat

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions