4

I have installed OpenCV from this doc with CMake . My ~/.profile file is :

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
export ARCHFLAGS="-arch i386 -arch x86_64"
export ARCHFLAGS="-arch i386" 
export VERSIONER_PYTHON_PREFER_64_BIT=yes
export VERSIONER_PYTHON_PREFER_32_BIT=no
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export PYTHONPATH=/Library/Python/2.6/site-packages:$PYTHONPATH    
export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib

With import cv I have this error:

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

My python architecture:

file "$( "$(which python)" -c "import sys;print(sys.executable)" )"
/usr/bin/python: Mach-O universal binary with 3 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
/usr/bin/python (for architecture ppc7400): Mach-O executable ppc

I have read and run all answers about OpenCV and Leopard in stackoverflow but still above error. Any help about this will be appreciated.

Thanks in advance

TheNone
  • 5,684
  • 13
  • 57
  • 98

1 Answers1

4

Leopard (and snow leopard) is a crossbreed, it contains both binaries: 32bit and 64bit... and it mixes them up... and its a nightmare. To my knowledge, you cannot mix 32bit and 64bit libraries in the same running program.

I have used this hack: How to force /usr/bin/gcc -> /usr/bin/gcc -m32?

It makes everything to compile in i386 (march 32 bit). You can also force it to 64 (not recommended). It fixes a lot of other compiling issues too. Remember, that this is a hack.

Backup /usr/bin/, do the hack, compile open cv and remove the hack.

Other solution is to upgrade to lion which (so far) seems not to have 32/64 bit problems.

Helpful commands also are:

lipo -info /usr/local/lib/python2.6/site-packages/cv2.so
arch -i386 /usr/bin/python

Lipo checks the architechture of shared objects and latter How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions. Maybe you can fix this by forcing python to the same arch as cv2...

EDIT

I noticed that you are using macport cv2 and apple python. Try /opt/local/bin/python2.6 when running the code.

Community
  • 1
  • 1
Juha
  • 2,053
  • 23
  • 44
  • ı have tried your hacks but didnt work for me. I have upgrade my system to lion because this installation problem is really a nightmare. Thanks for help. – TheNone May 21 '12 at 18:41
  • @TheNone: Did you get opencv working after upgrading to Mountain Lion? I just ran into the exact same problem; so I upgraded to Mountain Lion, brew uninstalled opencv, then brew installed it again. However, I still get an `ImportError: mach-o, but wrong architecture` – cooncesean Dec 03 '12 at 02:07
  • @cooncesean: Did you reinstall all the macports programs? If not, they all are still 32 bit (some might be 64bit) which causes the problems. – Juha Dec 03 '12 at 10:19
  • @Juha: I installed opencv and all of its dependencies via brew (cmake, jpeg, libtiff, eigen, tbb, libpng, and jasper). FWIW, I'm running on 64-bit architecture. – cooncesean Dec 04 '12 at 16:38
  • @cooncesean: One of the dependencies did not follow architecture (most likely bad Makefile/configure somewhere). It should give some library file e.g. `.so` when it complains about the arch. Use `lipo -info` command (see the answer) and hack the makefile/compiler (or send bug report to brew). – Juha Dec 08 '12 at 16:39
  • @Juha: I found that brew installing python solved my issue. Full details [here](https://github.com/mxcl/homebrew/issues/16016#issuecomment-11069520). – cooncesean Dec 09 '12 at 23:46