问题:从sklearn导入时出现ImportError:无法导入名称check_build
尝试从sklearn导入时出现以下错误:
>>> 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 superpack,scikit-learn-0.11我有一台Windows 7机器
我已经检查了几个有关此问题的答案,但没有一个给出解决此错误的方法。
I am getting the following error while trying to import from sklearn:
>>> 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
I am using python 2.7, scipy-0.12.0b1 superpack, numpy-1.6.0 superpack, scikit-learn-0.11
I have a windows 7 machine
I have checked several answers for this issue but none of them gives a way out of this error.
回答 0
Worked for me after installing scipy.
回答 1
>>> 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!
>>> 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
>>>
So, simply try to restart the shell!
回答 2
我针对Python 3.6.5 64位Windows 10的解决方案:
pip uninstall sklearn
pip uninstall scikit-learn
pip install sklearn
无需重新启动命令行,但是您可以根据需要执行此操作。我花了一天的时间来修复此错误。希望能有所帮助。
My solution for Python 3.6.5 64-bit Windows 10:
pip uninstall sklearn
pip uninstall scikit-learn
pip install sklearn
No need to restart command-line but you can do this if you want.
It took me one day to fix this bug. Hope this help.
回答 3
安装numpy
后scipy
,sklearn
仍然有错误
解:
设置Path
Python的系统变量和PYTHONPATH
环境变量
系统变量:添加C:\Python34
到路径中用户变量:添加新:(名称)PYTHONPATH
(值)C:\Python34\Lib\site-packages;
After installing numpy
, scipy
,sklearn
still has error
Solution:
Setting Up System Path
Variable for Python & the PYTHONPATH
Environment Variable
System Variables: add C:\Python34
into path
User Variables: add new: (name)PYTHONPATH
(value)C:\Python34\Lib\site-packages;
回答 4
通常,当我遇到此类错误时,打开__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的东西,它似乎并没有做任何事情,但调用预编译二进制 当然,这需要您自担风险,而且(肯定)可以解决。如果构建失败,您可能很快就会遇到其他更大的问题。
Usually when I get these kinds of errors, opening the __init__.py
file and poking around helps. Go to the directory C:\Python27\lib\site-packages\sklearn
and ensure that there’s a sub-directory called __check_build
as a first step. On my machine (with a working sklearn installation, Mac OSX, Python 2.7.3) I have __init__.py
, setup.py
, their associated .pyc
files, and a binary _check_build.so
.
Poking around the __init__.py
in that directory, the next step I’d take is to go to sklearn/__init__.py
and comment out the import statement—the check_build stuff just checks that things were compiled correctly, it doesn’t appear to do anything but call a precompiled binary. This is, of course, at your own risk, and (to be sure) a work around. If your build failed you’ll likely soon run into other, bigger problems.
回答 5
回答 6
从python.org安装新的64位版本的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
>>>
I had problems importing SKLEARN after installing a new 64bit version of Python 3.4 from python.org.
Turns out that it was the SCIPY module that was broken, and alos failed when I tried to “import scipy”.
Solution was to uninstall scipy and reinstall it with 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
>>>
回答 7
如果您使用Anaconda 2.7 64位,请尝试
conda upgrade scikit-learn
并重新启动python shell,对我有用。
当我遇到相同的问题并解决时,进行第二次编辑:
conda upgrade scikit-learn
对我也有用
If you use Anaconda 2.7 64 bit, try
conda upgrade scikit-learn
and restart the python shell, that works for me.
Second edit when I faced the same problem and solved it:
conda upgrade scikit-learn
also works for me
回答 8
没有其他答案对我有用。经过一番修补后,我卸载了sklearn:
pip uninstall sklearn
然后我从这里删除了sklearn文件夹:(调整系统和python版本的路径)
C:\Users\%USERNAME%\AppData\Roaming\Python\Python36\site-packages
并从此站点通过转轮安装了它:链接
该错误在那里可能是由于与其他地方安装的sklearn版本冲突。
None of the other answers worked for me. After some tinkering I unsinstalled sklearn:
pip uninstall sklearn
Then I removed sklearn folder from here: (adjust the path to your system and python version)
C:\Users\%USERNAME%\AppData\Roaming\Python\Python36\site-packages
And the installed it from wheel from this site: link
The error was there probably because of a version conflict with sklearn installed somewhere else.
回答 9
对我来说,我是通过使用最新的python版本(3.7)从全新安装Anaconda来将现有代码升级为新设置的,为此,
from sklearn import cross_validation,
from sklearn.grid_search import GridSearchCV
至
from sklearn.model_selection import GridSearchCV,cross_validate
For me,
I was upgrading the existing code into new setup by installing Anaconda from fresh with latest python version(3.7)
For this,
from sklearn import cross_validation,
from sklearn.grid_search import GridSearchCV
to
from sklearn.model_selection import GridSearchCV,cross_validate
回答 10
无需卸载然后重新安装sklearn
试试这个:
from sklearn.model_selection import train_test_split
no need to uninstall & then re-install sklearn
try this:
from sklearn.model_selection import train_test_split
回答 11
我在重新安装anaconda时遇到了同样的问题,为我解决了这个问题
i had the same problem reinstalling anaconda solved the issue for me
回答 12
在Windows中:
我试图从外壳中删除sklearn:pip卸载sklearn,然后重新安装它,但不起作用..
解决方案:
1- open the cmd shell.
2- cd c:\pythonVERSION\scripts
3- pip uninstall sklearn
4- open in the explorer: C:\pythonVERSION\Lib\site-packages
5- look for the folders that contains sklearn and delete them ..
6- back to cmd: pip install sklearn
In windows:
I tried to delete sklearn from the shell: pip uninstall sklearn, and re install it but doesn’t work ..
the solution:
1- open the cmd shell.
2- cd c:\pythonVERSION\scripts
3- pip uninstall sklearn
4- open in the explorer: C:\pythonVERSION\Lib\site-packages
5- look for the folders that contains sklearn and delete them ..
6- back to cmd: pip install sklearn