opencv / opencv/opencv-python

Getting error "A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.1 as it may crash" in 4.12.0.88

Open
#1,149 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.4k
Forks
1k
Avg merge
22h 17m
Merged PRs (30d)
3

Description

I am trying to install the latest version (4.12.0.88) with numpy 2.x but I get the following error saying the module is not compiled with 1.x.
If I understand correctly, 4.12.0.88 supports numpy 2.x. Can someone give my advice on how I can fix this issue without downgrading numpy to 1.x?

Reproduction code

$ uv run main.py

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.1 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/pi/developer/opencv-install-failure-repro/main.py", line 1, in <module>
    import cv2
  File "/home/pi/developer/opencv-install-failure-repro/.venv/lib/python3.11/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/pi/developer/opencv-install-failure-repro/.venv/lib/python3.11/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
  File "/home/pi/developer/opencv-install-failure-repro/main.py", line 1, in <module>
    import cv2
  File "/home/pi/developer/opencv-install-failure-repro/.venv/lib/python3.11/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/pi/developer/opencv-install-failure-repro/.venv/lib/python3.11/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: numpy.core.multiarray failed to import

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked opencv-install-failure-repro reproduction and run uv run main.py using NumPy 2.x and package version 4.12.0.88. Trace the import cv2 failure and the generated wheel or build configuration involved. Done means the reported reproduction imports cv2 successfully with NumPy 2.x without requiring a NumPy 1.x downgrade.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
build-system, computer-vision
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.