Python 从 sklearn 导入时出现导入错误:无法导入名称 check_build
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15274696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError in importing from sklearn: cannot import name check_build
提问by ayush singhal
I am getting the following error while trying to import from sklearn:
尝试从 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
我正在使用 python 2.7、scipy-0.12.0b1 superpack、numpy-1.6.0 superpack、scikit-learn-0.11 我有一台 Windows 7 机器
I have checked several answers for this issue but none of them gives a way out of this error.
我已经检查了这个问题的几个答案,但没有一个给出解决这个错误的方法。
采纳答案by Sawan
Worked for me after installing scipy.
安装 scipy 后为我工作。
回答by BenDundee
Usually when I get these kinds of errors, opening the __init__.pyfile and poking around helps. Go to the directory C:\Python27\lib\site-packages\sklearnand ensure that there's a sub-directory called __check_buildas 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 .pycfiles, and a binary _check_build.so.
通常,当我遇到此类错误时,打开__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.
Poking around the __init__.pyin that directory, the next step I'd take is to go to sklearn/__init__.pyand 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.
闲逛在__init__.py该目录中,我会采取下一步行动就是去sklearn/__init__.py进出import语句评论---只是检查,事情被正确编译check_build的东西,它似乎并没有做任何事情,但调用预编译二进制。当然,这需要您自担风险,并且(可以肯定)是一种解决方法。如果您的构建失败,您可能很快就会遇到其他更大的问题。
回答by Gurupad Hegde
>>> 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!
因此,只需尝试重新启动外壳即可!
回答by user3236650
After installing numpy, scipy,sklearnstill has error
安装numpy后scipy,sklearn还是有错误
Solution:
解决方案:
Setting Up System PathVariable for Python & the PYTHONPATHEnvironment Variable
Path为 Python 和PYTHONPATH环境变量设置系统变量
System Variables: add C:\Python34into path
User Variables: add new: (name)PYTHONPATH(value)C:\Python34\Lib\site-packages;
系统变量:添加C:\Python34到路径用户变量:添加新的:(名称)PYTHONPATH(值)C:\Python34\Lib\site-packages;
回答by user2314737
I had the same issue on Windows. Solved it by installing Numpy+MKL from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy(there it's recommended to install numpy+mkl before other packages that depend on it) as suggested by this answer.
我在 Windows 上遇到了同样的问题。按照这个答案的建议,通过从http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy安装 Numpy+MKL 解决了这个问题(建议在其他依赖它的软件包之前安装 numpy+mkl)。
回答by Statham
If you use Anaconda 2.7 64 bit, try
如果您使用 Anaconda 2.7 64 位,请尝试
conda upgrade scikit-learn
and restart the python shell, that works for me.
并重新启动 python shell,这对我有用。
Second edit when I faced the same problem and solved it:
当我遇到同样的问题并解决它时的第二次编辑:
conda upgrade scikit-learn
also works for me
也适用于我
回答by chross
None of the other answers worked for me. After some tinkering I unsinstalled sklearn:
其他答案都不适合我。经过一番修修补补,我卸载了 sklearn:
pip uninstall sklearn
Then I removed sklearn folder from here: (adjust the path to your system and python version)
然后我从这里删除了 sklearn 文件夹:(调整系统路径和 python 版本)
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.
错误可能是因为与安装在其他地方的 sklearn 存在版本冲突。
回答by John McCurdy
I had problems importing SKLEARN after installing a new 64bit version of Python 3.4 from python.org.
从 python.org 安装了新的 64 位版本的 Python 3.4 后,我在导入 SKLEARN 时遇到了问题。
Turns out that it was the SCIPY module that was broken, and alos failed when I tried to "import scipy".
原来是 SCIPY 模块坏了,当我尝试“导入 scipy”时也失败了。
Solution was to uninstall scipy and reinstall it with pip3:
解决方案是卸载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
>>>
回答by Ghanem
In windows:
在窗口中:
I tried to delete sklearn from the shell: pip uninstall sklearn, and re install it but doesn't work ..
我试图从 shell 中删除 sklearn:pip uninstall sklearn,然后重新安装它但不起作用..
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
回答by Loitd
My solution for Python 3.6.5 64-bit Windows 10:
我的 Python 3.6.5 64 位 Windows 10 解决方案:
pip uninstall sklearnpip uninstall scikit-learnpip install sklearn
pip uninstall sklearnpip uninstall scikit-learnpip 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.
无需重新启动命令行,但您可以根据需要执行此操作。我花了一天时间来修复这个错误。希望这有帮助。

