Problem with CV2 : numpy.core.multiarray failed to import

Viewed 12427

Tried to solve it with :

pip install -U numpy

but it still does not work.

That is what the console shows to me when I try to run the application :

    RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
  File "/Users/Rubio/Desktop/logistic-regression/train.py", line 8, in <module>
    import cv2
  File "/Library/Python/2.7/site-packages/cv2/__init__.py", line 3, in <module>
    from .cv2 import *
ImportError: numpy.core.multiarray failed to import
6 Answers

Uninstall & Install Numpy

conda uninstall numpy

conda install -c conda-forge numpy

it works

Reinstall OpenCV:

conda install -c anaconda opencv (for anaconda users)

I discovered that my problem was that I had two versions of numpy installed, I uninstall one of them and it worked normal.

I had a file named numbers.py in the same folder. Removing this file solved the issue for me.

Very strange, but worked.

Two solutions. I faced this problem with ai2thor environment.

  1. Just add import numpy.core.multiarray before the import cv2 statement
  2. Update number: pip install -U --no-cache-dir numpy==1.19.3
Related