How do I install libsvm for python under windows 7?
Asked Answered
I

5

11

Would like to know how to install libsvm for python under windows 7?

I downloaded the livsvm zip, but I don't understand the instructions included. I have placed the libsvm.dll in my c:\windows\system32 directory, but when I try

import svmutil

or

from svm import *

I get

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "svmutil.py", line 3, in <module>
    from svm import *
  File "svm.py", line 16, in <module>
    '../windows/libsvm.dll'))
  File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
Ingratitude answered 13/10, 2012 at 21:29 Comment(2)
This link will make the installation much clearer #12877667Brasier
The installation would be much clear with this link #12877667Brasier
K
4

I think there's no need to place the dll in the C:\windows\system32 directory unless you're using old versions of Windows (XP and older).

Make sure that:

  • You launch your python test script containing from svmutil import * inside the libsvm\python directory
  • You still have a copy of the libsvm dll in the libsvm\windows directory (if you moved it to C:\windows\system32, put a copy back in the libsvm\windows directory)

This works on my computer.

Knisley answered 13/10, 2012 at 22:13 Comment(3)
Strangely enough that works, but how do I avoid having to move all my programs to that directory?Ingratitude
Once you got that working, you can now move your program to another folder but make sure you include the libsvm/python folder using import sys and then sys.path.append('your_dir/libsvm/python').Knisley
Does however work if I make a directory called windows with the libsvm.dll in it, in my file's directoryIngratitude
P
12

SOLVED:
1. Navigate to http://www.lfd.uci.edu/~gohlke/pythonlibs/#libsvm
2. Download the .whl file of libsvm corresponding to your OS.
3. Open command prompt and navigate to that folder containing the downloaded .whl file.
4. Type the following command in command prompt-

pip install libsvm-3.20-cp27-none-win32.whl

NOTE: Type name of your .whl file after pip install

Pierides answered 2/9, 2015 at 16:23 Comment(1)
On Windows 10 this was the one that worked. I didn't debug why the above methods didn't work but this is easy.Encomiast
K
4

I think there's no need to place the dll in the C:\windows\system32 directory unless you're using old versions of Windows (XP and older).

Make sure that:

  • You launch your python test script containing from svmutil import * inside the libsvm\python directory
  • You still have a copy of the libsvm dll in the libsvm\windows directory (if you moved it to C:\windows\system32, put a copy back in the libsvm\windows directory)

This works on my computer.

Knisley answered 13/10, 2012 at 22:13 Comment(3)
Strangely enough that works, but how do I avoid having to move all my programs to that directory?Ingratitude
Once you got that working, you can now move your program to another folder but make sure you include the libsvm/python folder using import sys and then sys.path.append('your_dir/libsvm/python').Knisley
Does however work if I make a directory called windows with the libsvm.dll in it, in my file's directoryIngratitude
B
4

The best way I found to install libSVM on Windows, alongside other Python libraries, is to use unofficial Windows binaries, here:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#libsvm

This page provides 32- and 64-bit Windows binaries of many scientific open-source extension packages for the official CPython distribution of the Python programming language.

Most binaries are built from source code found on PyPI or in the projects public revision control systems. Source code changes, if any, have been submitted to the project maintainers or are included in the packages.

Many binaries depend on Numpy-MKL 1.8 and/or the Microsoft Visual C++ 2008 (64 bit or 32 bit, for CPython 2.6 to 3.2) or Visual C++ 2010 (64 bit or 32 bit, for CPython 3.3 and 3.4) redistributable packages.

Bullhorn answered 25/1, 2014 at 12:26 Comment(0)
L
3

I had a bunch of problems with this too on Windows 7 and libsvm 3.18, and none of the solutions above worked. It just couldn't find or didn't like the ../windows/libsvm.dll file no matter what file path gymnastics I tried. I was also running into 32-bit vs. 64-bit incompatibilities (my python is 64 bit).

I bracing myself for the pain of trying to recompile from visual studio, but this ended up being unnecessary. What ended up working for me was simply installing scikit-learn, which has libsvm included and nicely wrapped inside (http://scikit-learn.org/stable/index.html).

If you're using the Anaconda distro, like I was, this is extremely painless. Simply type conda install scikit-learn at a command line.

You can then import sklearn.svm.libsvm as svm and call it like just like you would libsvm, if you wish to ignore the other aspects of scikit-learn. It just works.

Lohner answered 23/5, 2014 at 17:22 Comment(0)
S
1

I know you asked this question 1 year ago, but I'd still like to post my solution, in case other people may benefit.

  1. Put libsvm to any place. Mine in C:\Python27\Lib\site-packages\libsvm-3.17

  2. Set PYTHONPATH in windows environment. Go to System Properties -> Advanced -> Environment variables.
    Add new variable, named PYTHONPATH, set value to C:\Python27\Lib\site-packages\libsvm-3.17\python.

Sheeree answered 6/10, 2013 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.