ImportError when importing from sklearn: unable to import name check_build

When trying to import from sklearn, the following error appears:

>>> 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, nump-1.6.0 superpack, scikit-learn-0.11 I have a windows 7 machine

I checked several answers for this problem, but none of them gives a way out of this error.

+102
python numpy scipy scikit-learn
mar 07 '13 at 15:12
source share
19 answers

Worked for me after installing scipy.

+139
Oct 08 '14 at 11:03
source share
 >>> 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 try reloading the shell!

+46
Jul 25 '13 at 22:53
source share

Reboot the python shell after installing scipy! You must not have restarted downtime after installation!

+25
Dec 11 '16 at 18:00
source share

After installing numpy , scipy , sklearn is still an error

Decision:

System Setup Path Variable for Python and PYTHONPATH Environment Variable

System variables: add C:\Python34 to the path User variables: add new: (name) PYTHONPATH (value) C:\Python34\Lib\site-packages;

+8
May 26 '15 at 1:02
source share

My solution for Python 3.6.5 64-bit Windows 10:

  1. pip uninstall sklearn
  2. pip uninstall scikit-learn
  3. pip install sklearn

There is no need to restart the command line, but you can do this if you want. It took me one day to fix this error. Hope this helps.

+6
Jun 06
source share

Usually, when I get such errors, opening the __init__.py file and gouging helps. Go to C:\Python27\lib\site-packages\sklearn and make sure that there is a subdirectory named __check_build as the first step. On my machine (with installed installation of sklearn, Mac OSX, Python 2.7.3) I have __init__.py , setup.py , their associated .pyc files and binary _check_build.so .

There will be __init__.py in this directory, the next step is to go to sklearn/__init__.py and comment on the import statement --- the check_build stuff just checks that things were compiled correctly, t seems to do nothing but call the precompiled binary. This, of course, at your own peril and risk, and, of course, work. If your build failed, you are likely to run into other, big problems.

+5
Mar 07 '13 at 16:02
source share

I had the same problem on windows. Solving it by installing Numpy + MKL from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy (it was recommended there to install numpy + mkl in front of other packages that depend on it), as this answer was suggested.

+3
Oct 10 '16 at 19:05
source share

Perhaps this is due to the fact that you may have scikit-learn installed along with sklearn. Run the following commands

  • pip uninstall scikit-learn
  • remove people sclearn
  • pip install sklearn

This solved the problem for me.

+3
Jun 27 '18 at 5:55
source share

I had problems importing SKLEARN after installing the new 64-bit version of Python 3.4 from python.org.

It turns out that it was a SCIPY module that was broken and alos failed when I tried to "import scipy".

The solution was to uninstall Scipy and reinstall it using 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 >>> 
+2
Jan 24 '18 at 14:54
source share

If you are using Anaconda 2.7 64 bit, try

 conda upgrade scikit-learn 

and restart the python shell that works for me.

Second edit, when I ran into the same problem and solved it:

 conda upgrade scikit-learn 

works for me too

+1
Mar 01 '17 at 1:58 on
source share

None of the other answers worked for me. After some picking, I removed the sclearn:

 pip uninstall sklearn 

Then I deleted the sklearn folder from here: (configure the path to your system and Python version)

 C:\Users\%USERNAME%\AppData\Roaming\Python\Python36\site-packages 

And installed it from the steering wheel from this site: link

The error was probably due to a version conflict with sklearn installed somewhere else.

+1
Jan 21 '18 at 13:59 on
source share

For me, I upgraded the existing code to a new installation, installing Anaconda from the latest version of Python latest (3.7). For this

 from sklearn import cross_validation, from sklearn.grid_search import GridSearchCV 

at

 from sklearn.model_selection import GridSearchCV,cross_validate 
+1
Feb 15 '19 at 6:18
source share

I ran into the same problem on my Windows machine and decided to solve it by installing the numpy + mkl package from http://www.lfd.uci.edu/~gohlke/pythonlibs/ . After installation, restart the shell.

0
Sep 23 '17 at 11:55 on
source share

In the windows:

I tried to remove sklearn from the shell: pip uninstall the sklearn program and reinstall it, but it does not work ..

decision:

 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 
0
Mar 24 '18 at 15:54
source share

I had a problem installing sklearn and trying to import datasets, the problem was compatibility with Cython. after creating a new env without cython, it worked like a charm.

0
Jun 15 '18 at 15:48
source share

I had the same problem, reinstalling the anaconda solved the problem for me

0
Nov 03 '18 at 14:57
source share

make sure your file you are encoding is not named "sklearn". I made the same mistake and now after renaming the file, it works fine

0
Feb 04 '19 at 14:12
source share

no need to uninstall and then reinstall sklearn

try this:

 from sklearn.model_selection import train_test_split 
0
Jun 17 '19 at 6:17
source share

I recently met the same error as you.

 Traceback (most recent call last): entFile "/Users/honey/Documents/machine_learning/task1/sklearn.py", line 8, in <module>er code here from sklearn import feature_extraction File "/Users/honey/Documents/machine_learning/task1/sklearn.py", line 8, in <module> from sklearn import feature_extraction ImportError: cannot import name 'feature_extraction' [Finished in 0.8s with exit code 1] [cmd: ['python3', '-u', '/Users/honey/Documents/machine_learning/task1/sklearn.py']] 

Then I discovered that python is confused by the name "sklearn.py", so the code cannot be executed correctly. I notice that you also have sclearn on your way

 C:\Python27\lib\site-packages\sklearn\__init__.py 

Therefore, perhaps you can try to avoid being β€œsklear” in your path to avoid ambiguity. Hope this helps. (I'm sorry that maybe I misunderstood the problem, and this may not help.)

-one
Apr 01 '18 at 10:12
source share



All Articles