Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anaconda doesn't find module cv2

I am using Anaconda on OS X Mavericks. When I try loading cv2 I get an import error (see below). Do you know how to fix this?

>>import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/Cellar/opencv/2.4.8.2/lib/python2.7/site-packages/cv2.so,    
2): Library not loaded: /usr/local/lib/libpng15.15.dylib
Referenced from: /usr/local/Cellar/opencv/2.4.8.2/lib/libopencv_highgui.2.4.dylib
Reason: image not found

I am not sure it's relevant, but in /usr/local/lib/ I have libpng16.16.dylib instead of libpng15.15.dylib.

like image 278
albus_c Avatar asked Mar 23 '14 09:03

albus_c


People also ask

How do I fix No module named cv2?

The Python "ModuleNotFoundError: No module named 'cv2'" occurs when we forget to install the opencv-python module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install opencv-python command.

Why can't I import cv2 in python?

importerror no module named cv2 error occurs when cv2 module is not properly installed or its path is not properly set or configured. The straight way fix for this error (no module named cv2) is to reinstall this module (OpenCV-python). In some scenario reinstalling this module automatically remove the older version.

Why is import cv2 not working Jupyter?

One of possibility is that you could have written import cv2 and its utilisation in separate cells of jupyter notebook. If this is the case then first run the cell having import cv2 part and then run the cell utilising the cv2 library.


Video Answer


2 Answers

This is the solution I found:

  • comment the PYTHONPATH environment in ~/.bash_profile, as suggested by @asmeurer
  • install opencv using https://binstar.org/jjhelmus/opencv
like image 125
albus_c Avatar answered Sep 22 '22 05:09

albus_c


As suggested in this issue, I fixed this problem by simply executing

conda update hdf5
like image 43
spacegoing Avatar answered Sep 21 '22 05:09

spacegoing