首页 文章

从sklearn导入时导入:无法导入名称check_build

提问于
浏览
93

尝试从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机器

我已经检查了这个问题的几个答案,但没有一个能解决这个问题 .

16 回答

  • 133

    通常当我遇到这些类型的错误时,打开 __init__.py 文件并且四处寻找帮助 . 转到目录 C:\Python27\lib\site-packages\sklearn 并确保第一步有一个名为 __check_build 的子目录 . 在我的机器上(使用工作sklearn安装,Mac OSX,Python 2.7.3)我有 __init__.pysetup.py ,它们关联的 .pyc 文件和二进制 _check_build.so .

    在该目录中查看 __init__.py ,我要采取的下一步是转到 sklearn/__init__.py 并注释掉import语句--- check_build的东西只是检查事情是否编译正确,它不会很快碰到其他,更大的问题 .

  • 3

    我在Windows上遇到了同样的问题 . 通过从http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy安装Numpy MKL解决了这个问题(建议在依赖它的其他软件包之前安装numpy mkl),如this answer所示 .

  • 0

    我的Python 3.6.5 64位Windows 10的解决方案:

    • pip uninstall sklearn

    • pip uninstall scikit-learn

    • pip install sklearn

    无需重新启动命令行,但如果需要,可以执行此操作 . 我花了一天时间修复这个bug . 希望这有帮助 .

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

    所以,只需尝试重启shell!

  • 8

    安装scipy后重启python shell!安装后你必须没有重新启动空闲!

  • 0

    安装 numpy 后, scipysklearn 仍然有错误

    解:

    设置系统 Path Python的变量和 PYTHONPATH 环境变量

    系统变量:将 C:\Python34 添加到路径用户变量中:添加新:(名称) PYTHONPATH (值) C:\Python34\Lib\site-packages;

  • 3

    安装scipy之后为我工作 .

  • 24

    从python.org安装新的64位版本的Python 3.4后,我在导入SKLEARN时遇到了问题 .

    原来是SCIPY模块被破坏了,当我试图“导入scipy”时alos失败了 .

    解决方法是卸载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
    >>>
    
  • 44

    这可能是因为您可能已经安装了scikit-learn和sklearn . 运行以下命令

    • pip uninstall scikit-learn

    • pip uninstall sklearn

    • pip install sklearn

    这解决了我的问题 .

  • 1

    如果您使用Anaconda 2.7 64位,请尝试

    conda upgrade scikit-learn
    

    并重新启动python shell,这对我有用 .

    当我遇到同样的问题并解决它时,第二次编辑:

    conda upgrade scikit-learn
    

    也适合我

  • 0

    我在Windows机器上遇到了同样的问题,并通过从http://www.lfd.uci.edu/~gohlke/pythonlibs/安装numpy mkl软件包解决了这个问题 . 安装完成后,重新启动shell .

  • 2

    在Windows中:

    我试图从shell中删除sklearn:pip uninstall sklearn,然后重新安装它但不起作用..

    解决方案:

    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

    我在安装sklearn时遇到问题并尝试导入数据集,问题是cython兼容性 . 在创建一个没有cython的新环境后,它就像一个魅力 .

  • -1

    没有其他答案对我有用 . 经过一些修补后我卸载了sklearn:

    pip uninstall sklearn
    

    然后我从这里删除了sklearn文件夹:(调整你的系统和python版本的路径)

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

    并从这个站点的车轮安装它:link

    错误可能是因为与其他地方安装的sklearn版本冲突 .

  • 5

    我有同样的问题重新安装anaconda解决了我的问题

  • 2

    最近我遇到了和你一样的错误 .

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

    然后我发现python被名称“sklearn.py”搞糊涂了,所以代码无法正确执行 . 我注意到你的路上还有sklearn

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

    所以也许你可以试着避免在你的道路上“sklearn”,以避免歧义 . 希望它可以提供帮助 . (对不起,或许我误解了这个问题,也许没有帮助 . )

相关问题