0

I am trying to install libsvm on my mac (OS-X 10.6.8). Libsvm installs fine for C++ (i can use svm-train, svm-predict binaries just fine). As per instructions I typed make in libsvm-3.12/python/ folder and got following output

<i>
make -C .. lib
if [ "Darwin" = "Darwin" ]; then \
        SHARED_LIB_FLAG="-dynamiclib -W1,-install_name,libsvm.so.2"; \
    else \
        SHARED_LIB_FLAG="-shared -W1,-soname,libsvm.so.2"; \
    fi; \
    g++ ${SHARED_LIB_FLAG} svm.o -o libsvm.so.2
</i>

But when I try using it in python via "import svmutil" I get following error

<i> 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "svmutil.py", line 3, in <module>
    from svm import *
  File "svm.py", line 19, in <module>
    '../libsvm.so.2'))
  File "/Library/Frameworks/Python.framework/Versions/7.1/lib/python2.7/ctypes/__init__.py", line 353, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(../libsvm.so.2, 6): no suitable image found.  Did find:
    ../libsvm.so.2: mach-o, but wrong architecture
</i>

I don't know how to get around this error. I tried compiling with -m64 and -arch x86_64 flags for g++ as well (during "Make" process of libsvm) but I continue to get this error. Can someone please tell me how to get around this issue?

1 Answers1

1

Try building libsvm as a Universal binary:

make CFLAGS='-arch i386 -arch x86_64' CXXFLAGS='-arch i386 -arch x86_64' LDFLAGS='-arch i386 -arch x86_64'

Alternately, ensure that you are running a suitable version of Python (check the Python interpreter's banner).

nneonneo
  • 171,345
  • 36
  • 312
  • 383
  • 1
    thanks for your reply. Just figured out what the issue was. My default python had been switched to 32 bit ( i had installed enthought's scipy/numpy package during which it changed my python's version to 32 bit). When I tried /usr/bin/python2.6 -c "import svmutil" it worked perfectly (/usr/bin/python2.6 is 64-bit python). – abhijit bendale Sep 24 '12 at 20:51
  • Your guess was correct. It was python 32 bit vs python 64 bit issue. – abhijit bendale Sep 24 '12 at 20:51