from sklearn import svm
导入 sklearn 模块时出现以下错误。
/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/isolve/iterative.py in <module>()
9
10 from scipy.sparse.linalg.interface import LinearOperator
---> 11 from scipy.lib.decorator import decorator
12 from .utils import make_system
13
ImportError: No module named decorator
ImportError Traceback (most recent call last)
<ipython-input-6-e938be4cf50b> in <module>()
----> 1 from sklearn import svm
/usr/local/lib/python2.7/dist-packages/sklearn/__init__.py in <module>()
54 # process, as it may not be compiled yet
55 else:
---> 56 from . import __check_build
57 from .base import clone
58 __check_build # avoid flakes unused variable error
ImportError: cannot import name __check_build
如何解决?
请您参考如下方法:
我之前也有同样的错误,要么是机器没有安装scipy包,要么是分布不对(取决于架构或操作系统)。
如果您的计算机中有 pip,请尝试使用以下命令安装 scipy:
sudo pip install scipy
如果您已经安装了它,请尝试升级或重新安装该软件包。
编辑:
按照@erip 建议的解决方案,您可以创建一个虚拟环境并测试保持 python 全局站点包目录清洁的解决方案:
virtualenv test # This creates a folder with the virtual env
source test/bin/activate
pip install scipy
pip install sklearn
停用和删除虚拟环境:
deactivate
rm -r test # Remove the folder
