ImportError in importing from sklearn: cannot import name check_build

286,531

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:

  1. pip uninstall sklearn
  2. pip uninstall scikit-learn
  3. 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.

Share:
286,531
ayush singhal
Author by

ayush singhal

Updated on September 24, 2021

Comments

  • ayush singhal
    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
    ayush singhal about 11 years
    I do not have _check_build.so in the folder , What can I do to get this for python 2.7
  • BenDundee
    BenDundee about 11 years
    Did you try commenting out the line that tries to import it in sklearn/__init__.py?
  • Andreas Mueller
    Andreas Mueller about 11 years
    For 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
    Basic over 9 years
    FWIW 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
    icedwater over 9 years
    Magic answers like this are not really helpful because they don't solve the problem. What if a restart doesn't fix it?
  • alexbw
    alexbw over 9 years
    Just mentioning that this happened to me with scikit-learn 0.15.2 compiled against numpy 1.9 and python 2.7.
  • Jared Forsyth
    Jared Forsyth about 9 years
    If you don't want to restart, del sys.modules['sklearn.__check_build']; import sklearn will also work
  • user3236650
    user3236650 about 8 years
    go to C:\Python34\Lib\site-packages\sklearn Double click init.py and setup.py.
  • mannuscript
    mannuscript over 6 years
    Plus restarting the python shell. :)
  • Punnerud
    Punnerud about 6 years
    Check 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
    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
    rwp almost 6 years
    If 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
    pylang over 5 years
    scipy.stats also did not work also raised an error. In my case, I had a file called multiprocessing.py in the same directory that somehow conflicted with the kernel's socket connection. Fixed by renaming the file multiprocessing_.py (leading underscore did not work).
  • Napuu
    Napuu over 3 years
    In Windows 10 I also had to enable long paths before executing these einstructions stackoverflow.com/questions/54778630/…