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?

4

2 に答える 2

1

ターゲットアーキテクチャに不一致があるようです。+universalバリアントを使用してmacportsにopencvをインストールしてみることができます。

もう1つのオプションは、Pythonのバージョンを更新することです。新しいバージョンもx86_64用にコンパイルされていると思います。

3番目の方法として、macportsに+python27を使用してopencvをインストールできます。次に、を実行してPythonのmacportsバージョンを選択できますsudo port select python27

于 2012-10-26T12:15:01.977 に答える
1

私の場合、どのアーチが一致するか:

$ 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

ただし、Python が 32 ビット モードで実行されることに注意してください。

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

修正:

$ VERSIONER_PYTHON_PREFER_32_BIT=0 python

また

$ defaults write com.apple.versioner.python Prefer-32-Bit -bool no
于 2013-07-21T01:53:46.097 に答える