2

I am porting a python+opencv app developped on windows to mac.

On windows i have the cv2.pyd in my virtualenv site-packages and it goes well.

I am new to mac and I don't understand hot it should work. I didn't find any binaries for opencv python bindings and it seems that the rightway is to use macport.

macport is copying the cv.py and cv2.so in the opts/.../site-packages.

At this point how to use it?

I tried to copy manually these two files but I am getting an error

>>> import cv
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/cv.py", line 1, in <module>
    from cv2.cv import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/cv2.so, 2): no suitable image found.  Did find:
        /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/cv2.so: mach-o, but wrong architecture

What's wrong?

Update: As asked by @Vortexfive:

$ file /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/cv2.so
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/cv2.so: Mach-O 64-bit dynamically linked shared library x86_64

$ file /Library/Frameworks/Python.framework/Versions/2.6/bin/python
/Library/Frameworks/Python.framework/Versions/2.6/bin/python: Mach-O universal binary with 2 architectures
/Library/Frameworks/Python.framework/Versions/2.6/bin/python (for architecture ppc):    Mach-O executable ppc
/Library/Frameworks/Python.framework/Versions/2.6/bin/python (for architecture i386):   Mach-O executable i386

It seems there is a mismatch. How to fix it?

2
  • 1
    Can you give the output of 'file /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/cv2.so' and 'file which python'. This sounds like a mismatch of the target architectures (i386,x86_64). Commented Oct 26, 2012 at 9:25
  • thanks. It seems there is a mismatch. see my update Commented Oct 26, 2012 at 9:44

2 Answers 2

1

It seems there's a mismatch in target architectures. You can try to install opencv in macports with the +universal variant.

Another option is to update your version of Python. Newer versions are compiled for x86_64 too I believe.

As a third alternative you can install opencv with the +python27 in macports. You can then select the macports version of Python by doing sudo port select python27.

Sign up to request clarification or add additional context in comments.

Comments

1

In my case, which the arch is matched:

$ file ../../release.mac/lib/cv2.so 
../../release.mac/lib/cv2.so: Mach-O 64-bit dynamically linked shared library x86_64
$ file `which python`
/usr/bin/python: Mach-O universal binary with 2 architectures
/usr/bin/python (for architecture x86_64):  Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386):    Mach-O executable i386

But not aware that the python run in 32 bit mode:

$ defaults read com.apple.versioner.python Prefer-32-Bit
1

Fixed by:

$ VERSIONER_PYTHON_PREFER_32_BIT=0 python

or

$ defaults write com.apple.versioner.python Prefer-32-Bit -bool no

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.