Python使用libsvm的“ImportError: No module named svmutil”问题

from:http://blog.csdn.net/xmu_jupiter/article/details/46830327

Windows下用Python使用libsvm库的时候,按照主流的方法(可以点击这里)安装配置,没有问题。但是,一旦不是在命令行而是在Python脚本中使用libsvm的时候,编会报错:”ImportError: No module named svmutil”。

这是因为在python中,每个py文件都被称为模块,而每个包含init.py文件的目录都被称为包。只要模块或包所在的目录位于sys.path中,就可以使用导入模块或导入包。如果它不在sys.path目录中,则需要手动添加。具体方法如下:

[En]

This is because in python, every py file is called a module, and every directory with a * init*.py file is called a package. You can use the import module or import package as long as the directory where the module or package is located is in sys.path. If it is not in the directory sys.path, you need to add it manually. The methods are as follows:

import sys
path = <span class="hljs-string">"C:\libsvm-3.20\python"
sys<span class="hljs-preprocessor">.path<span class="hljs-preprocessor">.append(path)</span></span></span>
  • 1
  • 2
  • 3

  • 1

  • 2
  • 3

上面的路径是我的libsvm中的Python目录。只要将这三行添加到脚本的开头,就可以在Python中正常使用libsvm。

[En]

Path above is the Python directory in my libsvm. As long as you add these three lines to the beginning of the script, you can use libsvm normally in Python.

此外

[En]

In addition

import <span class="hljs-built_in">os
<span class="hljs-built_in">os.chdir(path)</span></span>

不能起到添加搜索目录的效果,这只是为了切换程序执行目录,方便调用脚本中的外部文件。

[En]

Can not play the effect of adding a search directory, this is just to switch the program execution directory to facilitate the call of external files in the script.

Original: https://www.cnblogs.com/zhizhan/p/5956303.html
Author: 止战F
Title: Python使用libsvm的“ImportError: No module named svmutil”问题

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/6293/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

最近整理资源【免费获取】:   👉 程序员最新必读书单  | 👏 互联网各方向面试题下载 | ✌️计算机核心资源汇总