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

When will opencv-python support numpy 2.0? #997

Closed
risemeup1 opened this issue Jun 11, 2024 · 7 comments
Closed

When will opencv-python support numpy 2.0? #997

risemeup1 opened this issue Jun 11, 2024 · 7 comments
Assignees

Comments

@risemeup1
Copy link

risemeup1 commented Jun 11, 2024

Our paddle requires support for numpy 2.0, but paddle uses opencv-python. If paddle is compiled with numpy 2.0, it will conflict with opencv-python compiled under numpy 1.0.

@risemeup1 risemeup1 changed the title When will opencv-python be compatible with numpy 2.0? When will opencv-python support numpy 2.0? Jun 11, 2024
@asmorkalov asmorkalov self-assigned this Jun 16, 2024
@asmorkalov
Copy link
Collaborator

OpenCV team works on new packages release. As short term solution you can re-build OpenCV-Python package with Numpy 2 from sources.

@asmorkalov
Copy link
Collaborator

Error message for googling:

python3.9
Python 3.9.5 (default, Nov 23 2021, 15:27:38) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2 as cv

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/ksenia/.local/lib/python3.9/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/ksenia/.local/lib/python3.9/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, 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/ksenia/.local/lib/python3.9/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/ksenia/.local/lib/python3.9/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: numpy.core.multiarray failed to import

@asmorkalov
Copy link
Collaborator

#1001

@smeng9
Copy link

smeng9 commented Jun 17, 2024

Error message for googling:

python3.9
Python 3.9.5 (default, Nov 23 2021, 15:27:38) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2 as cv

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/ksenia/.local/lib/python3.9/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/ksenia/.local/lib/python3.9/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, 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/ksenia/.local/lib/python3.9/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/ksenia/.local/lib/python3.9/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ImportError: numpy.core.multiarray failed to import

I checked the source code https://github.com/opencv/opencv/blob/4bf95ac2df822db8608c94d891f5edf8c549a03f/modules/python/package/cv2/__init__.py#L12 seems this numpy.core.multiarray is only imported but not used anywhere.

@asmorkalov
Copy link
Collaborator

Patch: #1002
Release: https://github.com/opencv/opencv-python/releases/tag/84

@umayrh
Copy link

umayrh commented Jul 1, 2024

I still see this import error on Ubuntu 22.0.4 LTS - but not on macOS - because the build system is pulling numpy 2 instead of numpy 1.x:

Collecting opencv-python-headless==4.10.0.84 (from -r requirements.txt (line 28))
  Downloading opencv_python_headless-4.10.0.84-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (20 kB)
Collecting opencv-contrib-python-headless==4.10.0.84 (from -r requirements.txt (line 29))
  Downloading opencv_contrib_python_headless-4.10.0.84-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (20 kB)
Collecting numpy (from -r requirements.txt (line 43))
  Downloading numpy-2.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (60 kB)
...

RuntimeError: module compiled against ABI version 0x1000009 but this version of numpy is 0x2000000
ImportError while loading conftest '/home/runner/work/medical-document-ai/medical-document-ai/test/conftest.py'.
test/conftest.py:11: in <module>
    from src.app import (
src/app.py:23: in <module>
    from src.services.etl.scheduled_job import ScheduledJobManager
src/services/etl/scheduled_job.py:11: in <module>
    from src.services.etl.common.ocr_service import OCRService
src/services/etl/common/ocr_service.py:8: in <module>
    import cv2
/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/cv2/__init__.py:[18](https://github.com/umayrh/medical-document-ai/actions/runs/9734645918/job/26862931680#step:7:19)1: in <module>
    bootstrap()
/opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/cv2/__init__.py:153: in bootstrap
    native_module = importlib.import_module("cv2")
E   ImportError: numpy.core.multiarray failed to import

@cosmin-ciocan-navee
Copy link

Also see it on Ubuntu 22.04 with numpy >= 2.0:

import cv2
.venv-llm-classification/lib/python3.12/site-packages/cv2/__init__.py:181: in <module>
    bootstrap()
.venv-llm-classification/lib/python3.12/site-packages/cv2/__init__.py:153: in bootstrap
    native_module = importlib.import_module("cv2")
/usr/lib/python3.12/importlib/__init__.py:90: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
E   ImportError: numpy.core.multiarray failed to import

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

5 participants