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 compatible build #943

Closed
dkbarn opened this issue Jan 3, 2024 · 7 comments
Closed

Numpy 2 compatible build #943

dkbarn opened this issue Jan 3, 2024 · 7 comments
Assignees
Milestone

Comments

@dkbarn
Copy link

dkbarn commented Jan 3, 2024

I haven't managed to find any previous discussion about this, although I'm surprised by that so I very well may have missed it.

Numpy 2 is coming: numpy/numpy#24300

Are there any plans to begin providing nightly builds of OpenCV Python bindings which are ABI compatible with Numpy 2? Instructions are provided here on how to do that: https://numpy.org/devdocs/dev/depending_on_numpy.html#numpy-2-0-specific-advice

Currently when I pip install opencv-python-rolling it is not ABI compatible:

# create a virtualenv
$ python -m venv testvenv

# install numpy 2.x
$ testvenv/bin/pip install --pre -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple numpy

# install opencv-python-rolling
$ testvenv/bin/pip install opencv-python-rolling

$ testvenv/bin/python
>>> import cv2
RuntimeError: module compiled against ABI version 0x1000009 but this version of numpy is 0x2000000
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/share/dev/src/testvenv/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/share/dev/src/testvenv/lib/python3.10/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: numpy.core.multiarray failed to import
@asmorkalov asmorkalov self-assigned this Jan 6, 2024
@dkbarn
Copy link
Author

dkbarn commented Apr 3, 2024

Note that numpy 2.0.0rc1 is now publicly available: numpy/numpy#24300 (comment)

@nabobalis
Copy link

Is there anything we can do to help with checking support for numpy 2.0?

@asmorkalov
Copy link
Collaborator

2 items in scope:

@jakirkham
Copy link

JFYI NumPy is planning to release 2.0 on June 16th

xref: numpy/numpy#24300 (comment)

@dkbarn
Copy link
Author

dkbarn commented Jun 16, 2024

Numpy 2.0 is now live on PyPI and all pip installs of opencv-python are now broken. It's unclear to me why simply adding numpy<2 to the setup.py was not prioritized ahead of this date, there was plenty of forewarning and this situation was easily avoidable.

$ python -m venv venv

$ venv/bin/pip install opencv-python
Collecting opencv-python
  Downloading opencv_python-4.10.0.82-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (20 kB)
Collecting numpy>=1.21.2 (from opencv-python)
  Using cached numpy-2.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (60 kB)
Downloading opencv_python-4.10.0.82-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (62.5 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.5/62.5 MB 6.8 MB/s eta 0:00:00
Using cached numpy-2.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.0 MB)
Installing collected packages: numpy, opencv-python
Successfully installed numpy-2.0.0 opencv-python-4.10.0.82

$ venv/bin/python
Python 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2

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 "<stdin>", line 1, in <module>
  File "/home/user/venv/lib/python3.12/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/user/venv/lib/python3.12/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/venv/lib/python3.12/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/user/venv/lib/python3.12/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: numpy.core.multiarray failed to import

@braingram
Copy link

Any ETA for this?

@rgommers
Copy link

It's up on PyPI now, as announced in #997. Version 4.10.0.84

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

6 participants