QuanDT
QuanDT

Reputation: 29

Opencv3: Error when import cv2 in python OSX el capitan

I was installed OpenCV 3.1 on mac OSX, I also create a symlink in

/Library/Python/2.7/site-packages: 
cv2.so -> /usr/local/Cellar/opencv3/3.1.0_3/lib/python2.7/site-packages/cv2.so

But when I import cv2 in terminal i got this error:

>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.7/site-packages/cv2.so, 2): Library not loaded: /usr/local/opt/webp/lib/libwebp.6.dylib
  Referenced from: /usr/local/Cellar/opencv3/3.1.0_3/lib/libopencv_imgcodecs.3.1.dylib
  Reason: image not found

Then I tried to install webp using mac port:

sudo port install webp

But after that i still got the error above when import cv2 in python:

ImportError: dlopen(/Library/Python/2.7/site-packages/cv2.so, 2): Library not loaded: /usr/local/opt/webp/lib/libwebp.6.dylib

Upvotes: 2

Views: 2115

Answers (3)

Benyamin
Benyamin

Reputation: 410

you need to install brew install webp but for this lib you need to install libpng first with brew install libpng

if you are using this to install opencv you need to link! because you are tap in brew with brew tap homebrew/science for this use this:

brew link --overwrite libpng
brew link --overwrite webp

but first of all test without linking it should be enough (:

Upvotes: 0

Fabricio
Fabricio

Reputation: 76

I had the same issue, and after run brew install webp it simply fixed the import issue on python.

I hope this help you.

Upvotes: 2

QuanDT
QuanDT

Reputation: 29

I found the solution in here. Installed webp using macports not solve the problem, I have to install webp follow this step:

  • Download libwebp-0.5.1.tar.gz (not libwebp-0.5.1-mac-10.9.tar.gz) from here
  • Untar the package:

tar xvzf libwebp-0.5.1.tar.gz

  • Go to the directory where libwebp-0.5.1/ was extracted to and run the following commands:

    cd libwebp-0.5.1

    ./configure

    make

    sudo make install

That's work for me.

Upvotes: 0

Related Questions