Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numpy 2.0 support #229

Open
ericpre opened this issue Jun 8, 2024 · 7 comments
Open

Numpy 2.0 support #229

ericpre opened this issue Jun 8, 2024 · 7 comments

Comments

@ericpre
Copy link

ericpre commented Jun 8, 2024

Describe the bug
Support numpy 2.0.

To Reproduce

import quaternion

Give the following error with numpy 2.0.0rc2:

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0rc2 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 "C:\Users\M0041User\mambaforge\envs\np2\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\spyder_kernels\console\__main__.py", line 24, in <module>
    start.main()
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\spyder_kernels\console\start.py", line 331, in main
    kernel.start()
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\ipykernel\kernelapp.py", line 739, in start
    self.io_loop.start()
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\tornado\platform\asyncio.py", line 205, in start
    self.asyncio_loop.run_forever()
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\asyncio\base_events.py", line 603, in run_forever
    self._run_once()
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\asyncio\base_events.py", line 1909, in _run_once
    handle._run()
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\ipykernel\kernelbase.py", line 545, in dispatch_queue
    await self.process_one()
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\ipykernel\kernelbase.py", line 534, in process_one
    await dispatch(*args)
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\ipykernel\kernelbase.py", line 437, in dispatch_shell
    await result
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\ipykernel\ipkernel.py", line 362, in execute_request
    await super().execute_request(stream, ident, parent)
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\ipykernel\kernelbase.py", line 778, in execute_request
    reply_content = await reply_content
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\ipykernel\ipkernel.py", line 449, in do_execute
    res = shell.run_cell(
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\ipykernel\zmqshell.py", line 549, in run_cell
    return super().run_cell(*args, **kwargs)
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\IPython\core\interactiveshell.py", line 3075, in run_cell
    result = self._run_cell(
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\IPython\core\interactiveshell.py", line 3130, in _run_cell
    result = runner(coro)
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\IPython\core\async_helpers.py", line 129, in _pseudo_sync_runner
    coro.send(None)
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\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 "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\IPython\core\interactiveshell.py", line 3517, in run_ast_nodes
    if await self.run_code(code, result, async_=asy):
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\IPython\core\interactiveshell.py", line 3577, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "C:\Users\M0041User\AppData\Local\Temp\ipykernel_37580\3305195879.py", line 1, in <module>
    import quaternion
  File "C:\Users\M0041User\mambaforge\envs\np2\lib\site-packages\quaternion\__init__.py", line 27, in <module>
    from .numpy_quaternion import (
AttributeError: _ARRAY_API not found

Traceback (most recent call last):

  Cell In[3], line 1
    import quaternion

  File ~\mambaforge\envs\np2\lib\site-packages\quaternion\__init__.py:27
    from .numpy_quaternion import (

ImportError: numpy.core.multiarray failed to import

Expected behavior
A clear and concise description of what you expected to happen and why.

Environment (please complete the following information):

  • OS, including version: Windows 10
  • Installation method (conda, pip, or compiled from source): pip
  • Numpy version (use np.version.version): 2.0.0rc2
  • Quaternion version (use quaternion.__version__): 2023.0.3

Additional context
Add any other context about the problem here.

@moble
Copy link
Owner

moble commented Jun 14, 2024

I started an effort in this direction, but it's very difficult. Will probably need help from some numpy devs.

@moble
Copy link
Owner

moble commented Jun 19, 2024

See also quaternionic for a pure-python package I wrote that doesn't depend on numpy's C API.

@2sn
Copy link

2sn commented Jun 19, 2024

Now that Numpy 2+ is the official current release, finding a fix becomes urgent. I hope someone is able to help out. I have never done any programming with Numpy API, only use f2py.

@johann-petrak
Copy link

Until there is a solution for numpy 2.0.0 or higher, maybe add <2.0.0 to the requirements.txt file?

@2sn
Copy link

2sn commented Jun 24, 2024

For me, installing chainconsumer, which does require numpy < 2 does the trick.

But, yes, I think also adding it to numpy-quaternion directly would be useful.

@moble
Copy link
Owner

moble commented Jun 24, 2024

Unfortunately, because of how pip versioning works, I believe that only means that anyone with numpy 2 trying to install this package will just get the last version of this package that didn't include the restriction to numpy<2. But FWIW, I've added it now.

@2sn
Copy link

2sn commented Jun 24, 2024

You may be correct about that. Not sure how this can be fixed, there must be a way to modify past versions on PyPI - this would not be the first packages affected by incompatible changes of a dependent package. Rather, that must be the common case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants