Coder Social home page Coder Social logo

Comments (6)

asmorkalov avatar asmorkalov commented on July 22, 2024 1

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

from opencv-python.

asmorkalov avatar asmorkalov commented on July 22, 2024 1

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

from opencv-python.

asmorkalov avatar asmorkalov commented on July 22, 2024

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

from opencv-python.

asmorkalov avatar asmorkalov commented on July 22, 2024

#1001

from opencv-python.

smeng9 avatar smeng9 commented on July 22, 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.

from opencv-python.

umayrh avatar umayrh commented on July 22, 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

from opencv-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.