'Problem with CV2 : numpy.core.multiarray failed to import
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
Solution 1:[1]
Uninstall & Install Numpy
conda uninstall numpy
conda install -c conda-forge numpy
it works
Solution 2:[2]
Reinstall OpenCV:
conda install -c anaconda opencv (for anaconda users)
Solution 3:[3]
I discovered that my problem was that I had two versions of numpy installed, I uninstall one of them and it worked normal.
Solution 4:[4]
I had a file named numbers.py in the same folder. Removing this file solved the issue for me.
Very strange, but worked.
Solution 5:[5]
I faced this error with Tello Drone "DJITelloPy" and this solution from Soroush Karimi saved the day.
pip uninstall numpy
pip install numpy==1.19.3
Solution 6:[6]
Two solutions. I faced this problem with ai2thor environment.
- Just add import
numpy.core.multiarray
before the import cv2 statement - Update number:
pip install -U --no-cache-dir numpy==1.19.3
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DoEvent |
Solution 2 | Blue |
Solution 3 | Rafael Paixão |
Solution 4 | Ebin Zacharias |
Solution 5 | HassanSh__3571619 |
Solution 6 | John Doe |