ImportError in importing from sklearn: cannot import name check_build
Solution 1
Worked for me after installing scipy.
Solution 2
>>> 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!
Solution 3
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.
Solution 4
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;
Solution 5
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.
ayush singhal
Updated on September 24, 2021Comments
-
ayush singhal over 2 years
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.
-
ayush singhal about 11 yearsI do not have _check_build.so in the folder , What can I do to get this for python 2.7
-
BenDundee about 11 yearsDid you try commenting out the line that tries to import it in
sklearn/__init__.py
? -
Andreas Mueller about 11 yearsFor the moment, you can comment out the line that does the import, that should get you running. Can you then please open an issue in the issue tracker github.com/scikit-learn/scikit-learn/issues looks like a bug.
-
Basic over 9 yearsFWIW Commenting out the
import
in__init__.py
didn't fix the problem but did expose a different error - my scipy install had not succeeded. The error in the question was masking the real issue -
icedwater over 9 yearsMagic answers like this are not really helpful because they don't solve the problem. What if a restart doesn't fix it?
-
alexbw over 9 yearsJust mentioning that this happened to me with scikit-learn 0.15.2 compiled against numpy 1.9 and python 2.7.
-
Jared Forsyth about 9 yearsIf you don't want to restart,
del sys.modules['sklearn.__check_build']; import sklearn
will also work -
user3236650 about 8 yearsgo to C:\Python34\Lib\site-packages\sklearn Double click init.py and setup.py.
-
mannuscript over 6 yearsPlus restarting the python shell. :)
-
Punnerud about 6 yearsCheck if there is a file called "sklearn" in the same folder. Try running from a different folder. Solved it for me (my fault). Find file with <ls | grep -i "sklearn">
-
Abhimanu Kumar about 6 years@Mannu Yes; Also for me on jupyter notebook, just restarting (shutting down and click-open again) that ipynb py-kernel worked without restarting all of the jupyter notebook.
-
rwp almost 6 yearsIf you're essentially saying that the latest version of sklearn fixes the bug, it would be helpful to state which version numbers of sklearn you upgrade to. Thanks.
-
pylang over 5 years
scipy.stats
also did not work also raised an error. In my case, I had a file calledmultiprocessing.py
in the same directory that somehow conflicted with the kernel's socket connection. Fixed by renaming the filemultiprocessing_.py
(leading underscore did not work). -
Napuu over 3 yearsIn Windows 10 I also had to enable long paths before executing these einstructions stackoverflow.com/questions/54778630/…