How to install LIBSVM for Python

I built libsvm on Mac OS X using Make.

$ tar xzfv libsvm-3.17.tar.gz $ cd libsvm-3.17 $ make 

This created various libsvm executables:

 $ ls COPYRIGHT heart_scale svm-predict.c svm-train.c tools FAQ.html java svm-scale svm.cpp windows Makefile matlab svm-scale.c svm.def Makefile.win python svm-toy svm.h README svm-predict svm-train svm.o 

I am also related to this in /usr/local :

 $ ls -la /usr/local/ ... svm -> /usr/local/libsvm-3.17/ 

And added Python bindings to my path:

 import sys sys.path.append('/usr/local/svm/python') 

But Python bindings cannot find the "LIBSVM" library:

 $ python test.py Traceback (most recent call last): File "test.py", line 8, in <module> import svmutil File "/usr/local/svm/python/svmutil.py", line 5, in <module> from svm import * File "/usr/local/svm/python/svm.py", line 22, in <module> raise Exception('LIBSVM library not found.') Exception: LIBSVM library not found. 

Can someone tell me how to set this up? In python readme for libsvm the only description

 Installation ============ On Unix systems, type > make The interface needs only LIBSVM shared library, which is generated by the above command. We assume that the shared library is on the LIBSVM main directory or in the system path. 

What am I missing?

+6
source share
7 answers

Instead of going through libsvm to access it using Python (I installed libsvm via MacPorts and import svmutil ), you can install the popular scikit-learn , which contains an optimized version of libsvm with Python bindings .

Installation is very simple: MacPorts : sudo port install py27-scikit-learn (adapt py27 to any version of Python you use).

+8
source

If you need a solution other than MacPorts, see this page (especially the comment from Thanassis):

Install libsvm-3.0 for Python on OSX 10.6

Despite the title of the post, the solution worked for me on a CentOS machine with python 2.7.

+2
source

It looks like an old thread. Hope this helps someone else in the future.

I had the same problem. Decision

  • Run make in the libsvm-3.0 directory
  • Run make in the libsvm-3.0 / python directory

If you did this only in the libsvm-3.0 folder, you will run into this problem. Do this in both folders. Then everything will be fine.

+2
source

find_library in python considers files with a .so extension. For this to work correctly, you need to create libsvm.so:

% ln -s libsvm.so.2 libsvm.so

Then try again, it will work correctly.

+1
source

You do not need to use scikit learn to use libSVM. I had the same issue when loading libsvm modules via python. I cloned a project from github and ran it from the command line using make , and after setting up the environment, I got the same error.

I fixed the problem by installing libSVM via homebrew :

brew install libsvm

This does not include python specific binaries, so you still have to clone and make from github and set up the environment.

+1
source

You have to go into / python and make to create a .so file.

0
source

you can also try using homebrew to install libsvm, for example, 'brew install libsvm', then you can open the project file and copy the files' svmutil.py 'and' svm.py 'into the project floder, then you can use the command' from svmutil import * ', and perhaps this will be normal.

0
source

All Articles