Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Image not found' Error After Installing OpenCV Python Wheel on Mac

I was able to successfully install the OpenCV Wheel on my Mac, but when I try to import the module I receive the following error:

(python35) iMac > python
Python 3.5.4 |Anaconda custom (64-bit)| (default, Oct  5 2017, 
02:58:14) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2`
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File 
"/Users/AntoliMac01/Anaconda/anaconda/envs/python35/lib/python3.5/site-packages/cv2/__init__.py", line 4, in <module>
    from .cv2 import *
ImportError: dlopen(/Users/AntoliMac01/Anaconda/anaconda/envs/python35/lib/python3.5/site-packages/cv2/cv2.cpython-35m-darwin.so, 2): Library not loaded: /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage
  Referenced from: /Users/AntoliMac01/Anaconda/anaconda/envs/python35/lib/python3.5/site-packages/cv2/.dylibs/libavcodec.57.107.100.dylib
  Reason: image not found
>>> `

I downloaded the wheel from this site.

OS version:

(python35) iMac > sw_vers -productVersion
10.10.5
(python35) iMac > 

When I do the install I see no errors or other issues:

iMac > pip install opencv_python-3.3.1.11-cp35-cp35m-
 macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_
intel.macosx_10_10_x86_64.whl
Processing ./opencv_python-3.3.1.11-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Requirement already satisfied: numpy>=1.11.1 in /Users/AntoliMac01/Anaconda/anaconda/envs/python35/lib/python3.5/site-packages (from opencv-python==3.3.1.11)
Installing collected packages: opencv-python
Successfully installed opencv-python-3.3.1.11
iMac >

I tried the hack of linking the cv.so library, but no joy:

lrwxrwx---   1 AntoliMac01  staff        25 Dec 24 12:14 cv2.so -> cv2.cpython-35m-darwin.so

I've tried building via Homebrew with zero success.

I tried 'opencv_contrib' with the same result as above.

I've searched far-and-wide on the Internet but can't seem to find a solution. I'm utterly mystified.

Any help would be greatly appreciated.

Joe

like image 307
Joe Avatar asked Dec 24 '17 19:12

Joe


People also ask

How do I fix a cv2 error 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.


2 Answers

I am running Mac OS 10.10.13. I had the same problem as the original poster. I followed the first step given in the answer by "Razorcutter". I still got an error message. The error I got indicated that cv2 needed some OS code that was designed for Mac OS X 10.12.xx.

In order to get around actually installing a higher OS, I just installed an older version of opencv-python that was compatible with my operating system using the following code: pip3 install opencv-python==3.2.0.6 The available versions at the time of this posting are 3.1.0.4, 3.1.0.5, 3.2.0.6, 3.2.0.7, 3.2.0.8, 3.3.0.9, 3.3.0.10, 3.3.1.11, 3.4.0.12.

like image 79
zozo Avatar answered Oct 17 '22 04:10

zozo


I had a very similar problem!

I did two things to make it work

1) The CoreImage.framework is not in the right place, /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage. It is actually inside the /System/Library/Frameworks/QuartzCore.framework directory, so copy that into the right location

2) Then you will have to upgrade to latest Mac OS, i'm now on 10.13.2

After that, provided you have opencv installed, it should work.

like image 28
Razorcutter Avatar answered Oct 17 '22 05:10

Razorcutter