Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python cannot import opencv because it can't find libjpeg.8.dylib

Trying to get opencv for python working on Mac OSX - Mavericks but keep getting an image not found for libjpeg.8.dylib when doing import cv from python

(Recently updated from Mountain Lion)

This is what I did:

1.brew tap homebrew/science

2.brew install opencv

3.python

4.import cv

-got the following error:

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

  1. I looked for libjpeg.8.dylib and found it in /usr/local/Cellar/jpeg/8d/lib/ which, apparently, is not where libopencv_highgui.2.4.dylib is looking.

I'm a bit new to Mac OS and homebrew. Could anyone explain how to resolve this error and get opencv running? I have the python that comes preinstalled with Mac and them python installed by homebrew.

Thank you.

like image 567
user3919242 Avatar asked Aug 07 '14 16:08

user3919242


People also ask

Is OpenCV and cv2 same?

cv2 (old interface in old OpenCV versions was named as cv ) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet.

Does OpenCV support Python 3?

The nice thing with OpenCV is that it comes with a complete Python 3 library. The latest GeeXlab 0.29. 17.0 for Windows 64-bit comes with Python 3.8.


1 Answers

Just had a similar problem to this (in python import opencv was working for me one day, then the next it threw the same error you are reporting) and this solution just worked for me:

Upgrade your homebrew opencv eg.:

brew upgrade opencv (or in my case brew upgrade opencv3)

Hope this helps

like image 85
lampShadesDrifter Avatar answered Oct 17 '22 05:10

lampShadesDrifter