opencv install on osx no suitable image error

Question:

I have followed this tutorial to install opencv: https://medium.com/@nuwanprabhath/installing-opencv-in-macos-high-sierra-for-python-3-89c79f0a246a

I have two different virtual environments setup.

On one cv2 works fine.
On the other one I get:

ImportError: dlopen(/Users/me/.virtualenvs/py3cv/lib/python3.6/site-packages/cv2.so, 2): no suitable image found.  Did find:
/Users/me/.virtualenvs/py3cv/lib/python3.6/site-packages/cv2.so: mach-o, but wrong architecture
/usr/local/Cellar/opencv/3.4.1_5/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so: mach-o, but wrong architecture

the working interpreter shows:

Python 3.6.4 (default, Dec 25 2017, 14:57:56) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin

when I go into python.
when I run import ctypes;print(ctypes.sizeof(ctypes.c_void_p))
I get: 8

The breaking one shows:

Python 3.6.4 (v3.6.4:d48ecebad5, Dec 18 2017, 21:07:28) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin

when I run import ctypes;print(ctypes.sizeof(ctypes.c_void_p)):
I get: 4

any ideas what is going wrong?

output of name -a

Darwin MyMBP 17.5.0 Darwin Kernel Version 17.5.0: Fri Apr 13 19:32:32 PDT 2018; root:xnu-4570.51.2~1/RELEASE_X86_64 x86_64
Asked By: KillerSnail

||

Answers:

For an .so (shared object) to be successfully loaded by an executable, their architectures must match (on OSX, this can be extended to: the .so must "contain" the executable’s architecture – as an .so can bundle multiple architectures inside).

The OpenCV version that you installed is built for Intel 064bit (pc064). That’s why it works on the 064bit Python, but doesn’t on 032bit one.

For more details on Python architecture, check [SO]: How do I determine if my python shell is executing in 32bit or 64bit mode on OS X? (@CristiFati’s answer).
Also, [SO]: Install win32com on MacOs and Linux (@CristiFati’s answer) might contain some useful info.

Answered By: CristiFati
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.