Programing

sklearn에서 가져 오기에서 ImportError : 이름 check_build를 가져올 수 없습니다

crosscheck 2020. 8. 5. 07:49
반응형

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 컴퓨터가 있습니다.

이 문제에 대한 몇 가지 답변을 확인했지만 아무도이 오류에서 벗어날 수 없습니다.


scipy를 설치 한 후 나를 위해 일했습니다.


>>> 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
>>> 

따라서 간단히 쉘을 다시 시작하십시오!


scipy를 설치 한 후 파이썬 쉘을 다시 시작하십시오! 아직 설치 한 후 유휴 상태를 다시 시작하지 않았어야합니다!


설치 후 numpy, scipy, sklearn여전히 오류가

해결책:

PathPython 및 PYTHONPATH환경 변수에 대한 시스템 변수 설정

시스템 변수 : C:\Python34경로에 추가 사용자 변수 : 새로 추가 : (이름) PYTHONPATH(값)C:\Python34\Lib\site-packages;


Python 3.6.5 64 비트 Windows 10에 대한 내 솔루션 :

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

명령 줄을 다시 시작할 필요는 없지만 원하는 경우이 작업을 수행 할 수 있습니다. 이 버그를 고치는 데 하루가 걸렸습니다. 이 도움을 바랍니다.


일반적으로 이러한 종류의 오류가 발생하면 __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 물건은 일이 올바르게 컴파일되었는지 확인하고 아무것도하지 않는 것으로 보입니다. 이진. 물론 이것은 당신 자신의 책임이며 (확실히) 해결해야 할 일입니다. 빌드가 실패하면 곧 더 큰 다른 문제가 발생할 수 있습니다.


아마도 sklekit과 함께 scikit-learn이 설치되어 있기 때문일 수 있습니다. 다음 명령을 실행하십시오

  • pip uninstall scikit-learn 제거
  • 핍 설치 제거
  • 핍 설치 sklearn

이것은 나를 위해 문제를 해결했습니다.


Windows에서 동일한 문제가 발생했습니다. 이 답변에서 제안한대로 http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy 에서 Numpy + MKL을 설치하여 해결했습니다 (이에 의존하는 다른 패키지보다 numpy + mkl을 설치하는 것이 좋습니다) .


python.org에서 새로운 64 비트 버전의 Python 3.4를 설치 한 후 SKLEARN을 가져 오는 데 문제가있었습니다.

SCIPY 모듈이 고장 났으며 "scipy 가져 오기"를 시도했을 때도 실패했습니다.

해결책은 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
>>>

Anaconda 2.7 64 비트를 사용하는 경우 시도하십시오

conda upgrade scikit-learn

파이썬 쉘을 다시 시작하면 저에게 효과적입니다.

동일한 문제에 직면하여 해결했을 때 두 번째 편집 :

conda upgrade scikit-learn

또한 나를 위해 작동


다른 답변들 중 어느 것도 나를 위해 일하지 않았습니다. 땜질 후 나는 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.


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

no need to uninstall & then re-install sklearn

try this:

from sklearn.model_selection import train_test_split

I faced the same issue in my Windows machine and got it solved by installing numpy+mkl package from http://www.lfd.uci.edu/~gohlke/pythonlibs/. After installation, restart the shell.


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

i had an issue when installed sklearn and try to import datasets the problem was cython compatibility. after creating a new env without cython it worked like a charm.


i had the same problem reinstalling anaconda solved the issue for me


make sure your file in which you are coding is not named as "sklearn". I did the same mistake and now after renaming the file, it is working fine


Recently I met the same mistike 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 found that python is confused by the name "sklearn.py",so the code can not be executed correctly. I notice that there is also sklearn in your path

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

So perhaps you can try to avoid "sklearn" in your path to avoid ambiguity. Hope it can help. (I am sorry that perhaps I misunderstood the problem and it may not help.)

참고URL : https://stackoverflow.com/questions/15274696/importerror-in-importing-from-sklearn-cannot-import-name-check-build

반응형