我在使用django时遇到了以下错误:
Exception Type: ImportError
Exception Value: No module named sparse
导入错误来自:
from sklearn.svm.sparse import LinearSVC
from nltk.classify.scikitlearn import SklearnClassifier
为了解决这个问题,我正在尝试通过以下方式安装 scikit-learn 的稀疏模块:
sudo easy_install scikits.sparse
但是我收到此错误:
no previously-included directories found matching 'doc/_build'
warning: no previously-included files matching '*~' found anywhere in distribution
warning: no previously-included files matching '*.so' found anywhere in distribution
warning: no previously-included files matching '*.pyc' found anywhere in distribution
clang: error: no such file or directory: 'scikits/sparse/cholmod.c'
clang: error: no input files
error: Setup script exited with error: command 'clang' failed with exit status 1
如何解决这个问题?
谢谢。
更改
from sklearn.svm.sparse import LinearSVC
自
from sklearn.svm import LinearSVC
忘记scikits.sparse
,这与scikit-learn无关。sklearn.svm.sparse
模块在几个版本前从scikit-learn中删除。
对安装 scikits.sparse 特别感兴趣的人。我在Mac OS X 10.9中遇到了问题。问题与设置工具根据您是否安装了Cython和Pyrex做出假设有关。
一个解决方案,当然不是最好的解决方案(对我有用)是安装 Pyrex。对于 macports 用户:
sudo port install py27-pyrex
安装 SparseSuite。
编辑 setup.py 文件,以便ext_modules的值如下:
ext_modules = [
Extension("scikits.sparse.cholmod",
["scikits/sparse/cholmod.pyx"],
libraries=["cholmod"],
include_dirs=[np.get_include(), "path/to/sparsesuite/include"],
library_dirs=["path/to/sparsesuite/lib"]
),
]
对我来说,SparseSuite 的包含和库目录是 usr/local/include 和/usr/local/lib。
在scikits/sparse/cholmod.pyx文件中编辑以下行:
cdef extern from "sparsesuite/cholmod.h":
自
cdef extern from "cholmod.h":
然后尝试再次安装 scikits.sparse。应该工作。