导入错误从sklearn导入:不能导入名称check_build

问题描述:

尝试从sklearn进口我收到以下错误:导入错误从sklearn导入:不能导入名称check_build

>>> from sklearn import svm 

Traceback (most recent call last): 
    File "<pyshell#17>", line 1, in <module> 
    from sklearn import svm 
    File "C:\Python27\lib\site-packages\sklearn\__init__.py", line 16, in <module> 
    from . import check_build 
ImportError: cannot import name check_build 

我使用python 2.7,SciPy的-0.12.0b1 superpack,numpy的-1.6。 0超级包装,scikit-learn-0.11 我有一台Windows 7机器

我已经检查了这个问题的几个答案,但没有一个给出了一个出路这个错误。

+0

尝试更新scikit学习到最新的版本(0.13)。 – adrianp 2013-03-07 15:15:13

+0

现在我收到以下错误 – 2013-03-07 15:16:46

+0

ImportError:无法导入名称__check_build而不是check_build – 2013-03-07 15:17:25

安装scipy后为我工作。

+4

加上重新启动python shell。 :) – Mannu 2018-01-07 09:36:56

+0

检查在同一个文件夹中是否有名为“sklearn”的文件。尝试从其他文件夹运行。为我解决了(我的错)。用 Punnerud 2018-03-03 11:50:43

通常,当我收到这些错误时,打开__init__.py文件并拨动帮助。转到目录C:\Python27\lib\site-packages\sklearn,并确保有一个名为__check_build的子目录作为第一步。在我的机器上(使用sklearn安装,Mac OSX,Python 2.7.3),我有__init__.py,setup.py,其关联的.pyc文件和二进制文件_check_build.so

在那个目录中查找__init__.py,下一步我要去sklearn/__init__.py并注释掉import语句--- check_build只是检查是否编译正确,看起来不是除了调用预编译的二进制文件以外,什么都不做当然,这是您自己承担的风险,并且(可以肯定)是一种解决方法。如果你的构建失败了,你很可能很快会遇到其他更大的问题。

+0

我没有_check_build.so在文件夹中,我能做些什么来获得这个蟒蛇2.7 – 2013-03-07 16:09:38

+0

你尝试评论试图将其导入'sklearn/__init __。py'? – BenDundee 2013-03-07 18:18:14

+2

目前,您可以注释掉导入的行,这会让您运行。那么你可以在问题跟踪器中打开一个问题https://github.com/scikit-learn/scikit-learn/issues看起来像一个错误。 – 2013-03-09 11:35:46

>>> from sklearn import preprocessing, metrics, cross_validation 

Traceback (most recent call last): 
    File "<pyshell#6>", line 1, in <module> 
    from sklearn import preprocessing, metrics, cross_validation 
    File "D:\Python27\lib\site-packages\sklearn\__init__.py", line 31, in <module> 
    from . import __check_build 
ImportError: cannot import name __check_build 
>>> ================================ RESTART ================================ 
>>> from sklearn import preprocessing, metrics, cross_validation 
>>> 

因此,只需尝试重新启动shell!

+7

这样的魔术答案并不真正有用,因为它们不能解决问题。如果重新启动不能解决问题会怎样? – icedwater 2014-09-23 08:41:42

+3

只是提到这发生在我用scikit学习0.15.2编译numpy 1.9和python 2.7。 – alexbw 2014-10-09 14:13:37

+2

如果你不想重启,'del sys.modules ['sklearn .__ check_build'];进口sklearn'也将工作 – 2015-03-23 22:55:05

安装后numpyscipysklearn仍然有错误

解决方案:

设置系统Path变量的Python &的PYTHONPATH环境变量

系统变量:新增C:\Python34到路径 用户变量:新增:(名称)PYTHONPATH(值)C:\Python34\Lib\site-packages;

+0

转到C:\ Python34 \ Lib \ site-packages \ sklearn双击_init_.py和setup.py。 – user3236650 2016-03-15 01:15:04

+0

这样做,谢谢!它适用于pycharm – 2018-03-06 15:53:45

我在Windows上遇到了同样的问题。通过安装Numpy + MKL从http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy解决它(建议在其他包依赖它的其他包之前安装numpy + mkl),如this answer所示。

安装scipy后重新启动python shell!安装完成后,您一定还没有重新启动闲置!

+1

这有助于,谢谢bro〜 – KAs 2017-11-25 10:14:41

如果您使用Anaconda 2.7 64位,尽量

conda upgrade scikit-learn 

,并重新启动Python Shell中,为我的作品。

我在我的Windows机器上遇到了同样的问题,并通过安装来自http://www.lfd.uci.edu/~gohlke/pythonlibs/的numpy + mkl包解决了它。安装后,重新启动外壳。

没有其他答案为我工作。一些修修补补之后我unsinstalled sklearn:

pip uninstall sklearn 

然后,我从这里取出sklearn文件夹:(调整路径系统和Python版本)

C:\Users\User\AppData\Roaming\Python\Python36\site-packages 

而从这个网站车轮安装了它: link

可能是因为与其他地方安装的sklearn版本冲突导致的错误。

从python.org安装新的Python 3.4版本后,导入SKLEARN时出现问题。

原来,这是SCIPY模块坏了,当我尝试“导入scipy”时,alos失败。

的解决办法是卸载SciPy的与PIP3重新安装:

C:\> pip uninstall scipy 

[lots of reporting messages deleted] 

Proceed (y/n)? y 
    Successfully uninstalled scipy-1.0.0 

C:\Users\>pip3 install scipy 

Collecting scipy 
    Downloading scipy-1.0.0-cp36-none-win_amd64.whl (30.8MB) 
    100% |████████████████████████████████| 30.8MB 33kB/s 
Requirement already satisfied: numpy>=1.8.2 in c:\users\johnmccurdy\appdata\loca 
l\programs\python\python36\lib\site-packages (from scipy) 
Installing collected packages: scipy 
Successfully installed scipy-1.0.0 

C:\Users>python 
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] 
on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import scipy 
>>> 
>>> import sklearn 
>>>