Reputation: 109
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
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
/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.
Upvotes: 10
Views: 10253
Reputation: 4416
I had a similar problem with the Pillow library on macOS. The solution proposed here to install it from source worked for me. I had to install it to /usr/local/
for Pillow to find it. You'll need command-line tools, which is the purpose of the first line:
xcode-select --install
curl -O -J -L http://www.ijg.org/files/jpegsrc.v8.tar.gz
tar xvfz jpeg*tar.gz # Unzip and untar what you downloaded
cd jpeg-8 # Change directory to wherever it unpacked to
./configure --prefix="/usr/local" # Configure with the necessary prefix
make
sudo make install
Upvotes: 0
Reputation: 4149
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
Upvotes: 3
Reputation: 481
I used brew a for installing OpenCV on my mac, and ran into this same problem, but it was with an Xcode C++ console application.
However an alternative method to solve the problem is to copy cp
the file to the library location.
cp /usr/local/Cellar/jpeg/8d/lib/libjpeg.8.dylib /usr/local/lib/libjpeg.8.dylib
Or the latter, which I don't suggest, just stating another method is to use move mv
the entire file location into your /usr/local/lib/ directory.
mv /usr/local/Cellar/jpeg/8d/lib/libjpeg.8.dylib /usr/local/lib/
Upvotes: 6
Reputation: 151
The quick and dirty solution for this is to make a symlink inside of the /usr/local/lib folder pointing to the actual location of libjpeg.8.dylib, like this:
$ sudo ln -s /usr/local/Cellar/jpeg/8d/lib/libjpeg.8.dylib /usr/local/lib/libjpeg.8.dylib
The problem is opencv and python expect libjpeg.8.dylib to be in /usr/local/lib/ but homebrew installs it in /usr/local/Cellar/, hence annoying error.
Upvotes: 14