Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named cv2

I've been trying to figure this error out for the past day and I've looked up error messages all over the internet and still can't figure out how to get past this error.

I have OpenCV and cv2 setup on my desktop, but I need to program on my laptop now (for mobile reasons). Unfortunately, even though I have OpenCV downloaded, when I try to import cv2, it gives me the error message, "ImportError: No module named cv2".

The closest I've gotten so far is "locate cv2" which gives me "/usr/lib/python2.7/dist-packages/cv2.so". I then go into the python shell and run "import sys" then "sys.path.append('/usr/lib/python2.7/dist-packages')" which then gives me a True when I ask "'/usr/lib/python2.7/dist-packages' in sys.path". However, when I then try to import cv2, it now returns a new error message of "ImportError: numpy.core.multiarray failed to import". I tried resolving this error, but I had no luck on this either.

I've tried everything on forums and message boards online and can't figure out how to fix this. ANY help would be extremely appreciated, as I need to complete this program by the end of the week.

like image 473
Alwin Hui Avatar asked Mar 18 '15 06:03

Alwin Hui


1 Answers

Another reason might be a missing OpenCV module. On my Mac OSX El Capitan [10.11.2 (15C50)], I had the exact same error with Anaconda install, and this resolved the issue:

conda install opencv

While that helped deal with:

ImportError: No module named cv2

It also introduced the following issue:

ImportError: numpy.core.multiarray failed to import

because somehow the numpy version got switched back to 1.7.0. So performing this, worked:

conda update numpy

Double check:

import numpy
print numpy.__version__
1.10.2

Now all good.

like image 89
Kingz Avatar answered Oct 23 '22 16:10

Kingz