5

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.

Jake Burkhead
  • 6,435
  • 2
  • 21
  • 32
albus_c
  • 6,292
  • 14
  • 36
  • 77
  • 1
    Just as a workaround, have you tried getting [a copy of libpng16](https://github.com/anura-engine/anura/blob/master/MacOS/dylibs/libpng16.16.dylib) in place and seeing if that would work? Or modifying the import to load libpng15 instead? I don't have a mac to test it but if nothing else works you might get help from [their issue tracker](https://github.com/ContinuumIO/anaconda-issues). – KobeJohn Mar 23 '14 at 13:11
  • Thanks for the tip! Now I get this error: `>>> import cv2 Traceback (most recent call last): File "", line 1, in 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: Incompatible library version: libopencv_highgui.2.4.dylib requires version 34.0.0 or later, but libpng15.15.dylib provides version 27.0.0` – albus_c Mar 23 '14 at 14:37
  • 1
    It seems pretty clear that it's just dependencies although I don't know why the dependency problem popped up in the first place. 15 is too old so try 16 from the link. Maybe try with another mac if you can get one or try the issue tracker. Hopefully somebody with a mac can get you some better advice. – KobeJohn Mar 23 '14 at 15:35
  • 2
    Your anaconda is trying to load the cv from Homebrew, which is why it isn't working. This is likely because you have the `PYTHONPATH` environment variable set. – asmeurer Mar 24 '14 at 15:59
  • 1
    I don't know if it will work, but you can try installing opencv from here https://binstar.org/jmargeta/opencv (there are instructions how to conda install it on that page). – asmeurer Mar 24 '14 at 16:00
  • This is the solution I found: – albus_c Mar 25 '14 at 09:59

3 Answers3

7

This is the solution I found:

albus_c
  • 6,292
  • 14
  • 36
  • 77
  • 1
    This needs to be seen more, because this is the only solution out of the 15 'solutions' I looked at that actually worked – James Tobin Jan 28 '15 at 21:44
1

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

conda update hdf5
spacegoing
  • 5,056
  • 5
  • 25
  • 42
0

you could also just add it to your PYTHONPATH. here's how: you should be able to get it to load through one of the other (non anaconda) python executables. mine were located at: /usr/bin/python (default system python) and /usr/local/bin/python (brew)

  • call the python executable using the full path
  • once you successfully import cv2 run: cv2.__file__ this will give you the file's path which you can then take (full directory path not including filename) and add as the first argument to your PYTHONPATH defined in ~/.bash_profile
  • after changing the .bash_profile don't forget to run source ~/.bash_profile to make the changes effective
  • fire up anaconda python and it should now find cv2
Gil Hiram
  • 492
  • 5
  • 13