导入sklearn

时间:2016-04-14 17:38:04

标签: python scikit-learn

使用pip install -U scikit-learn安装scikit-learn之后,我无法调用import sklearn:

>>> import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\sklearn\__init__.py", line 57, in <module>
  from .base import clone
File "C:\Python27\lib\site-packages\sklearn\base.py", line 9, in <module>
  from scipy import sparse
File "C:\Python27\lib\site-packages\scipy\sparse\__init__.py", line 214, in <module>
  from .csr import *
File "C:\Python27\lib\site-packages\scipy\sparse\csr.py", line 13, in <module>
  from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
ImportError: DLL load failed: %1 is not a valid Win32 application.

我该如何克服这个错误?

1 个答案:

答案 0 :(得分:1)

您可以尝试使用Anaconda创建虚拟环境,然后通过conda而不是pip安装sklearn

https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/20/conda/ http://conda.pydata.org/docs/using/pkgs.html#install-a-package

conda create -n yourenvname python=3.5 anaconda
conda install -n yourenvname sklearn