sklearn ImportError: 找不到名为_check_build的模块

13

我正在尝试导入sklearn,但是当我尝试这样做时,我收到以下提示:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-8fd979e02004> in <module>()
----> 1 import sklearn

C:\Users\Alpine\AppData\Local\Enthought\Canopy\User\sklearn\__init__.py in <module>()
     29     # process, as it may not be compiled yet
     30 else:
---> 31     from . import __check_build
     32     from .base import clone
     33 

C:\Users\Alpine\AppData\Local\Enthought\Canopy\User\sklearn\__check_build\__init__.py in <module>()
     44     from ._check_build import check_build
     45 except ImportError as e:
---> 46     raise_build_error(e)

C:\Users\Alpine\AppData\Local\Enthought\Canopy\User\sklearn\__check_build\__init__.py in raise_build_error(e)
     39 to build the package before using it: run `python setup.py install` or
     40 `make` in the source directory.
---> 41 %s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
     42 
     43 try:

ImportError: No module named _check_build
___________________________________________________________________________
Contents of C:\Users\Alpine\AppData\Local\Enthought\Canopy\User\sklearn\__check_build:
setup.py                  setup.pyc                 _check_build.c
_check_build.pyx          __init__.py               __init__.pyc
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.

If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.

ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line string', (1, 2))

我相当确信scikit-learn已经被正确构建,因为我成功运行了python setup.py install而没有发生任何事情。不过,我尝试运行python setup.py bdist_wininst -b doc/logos/scikit-learn-logo.bmp,但在 error: cannot copy tree 'build\scripts.win-amd64-2.7': not a directory 处被中断。

有人有什么想法可以解决这个问题吗?

7个回答

9

我在Windows 10上遇到了同样的问题。我安装了Python 3.7的Anaconda,但这个安装包不仅带来了这个问题。要解决这个问题,请在Anaconda提示符中运行:

conda install scikit-learn

至少对我有效


3

好的,下面是我的工作:

sudo make
sudo python setup.py install

最后,为了测试安装是否成功:

nosetests --exe sklearn

1
哦,太好了。它起作用了。"sudo make" 是什么意思? - spritecodej
@RyanLiu 你想要安装什么? - vineeshvs

2

避免这种错误的一种方法是确保您已安装所有所需的依赖项。在Ubuntu / Debian下,您可以通过运行以下命令来完成:

sudo apt-get build-dep python-sklearn

0

这并不完全符合您的问题,因为它不涉及Enthought分发;然而,我使用sklearn模块时遇到了类似的问题。错误信息大致如下:

$ python -m somefile.py           // somefile.py uses sklearn at some point
Cannot import name __check_build

我安装了scikit-learn(还有scipynumpy-MKL)从this page之后,问题似乎消失了。


0

我正在使用Anaconda,这对我有效:

conda install scikit-learn

0
在我的情况下,我安装了两个Python版本,第一个是我自己独立安装的Python,它位于一个单独的文件夹中;第二个是通过Anaconda安装的Python,它安装在其自己的文件夹中。因此,每次我调用Scikit Learn时,它都会引用第一个Python文件夹,这与Scikit Learn存在一些问题,但当我完全删除旧的Python文件夹后,Jupyter Notebook就会引用正确的Python文件夹,因此它可以正常工作。

0

确保您正在最新版本的Python下执行代码。如果您的计算机上安装了多个Python版本,则只需删除第一行“#!/usr/bin/python”,并尝试使用最新Python版本的完整路径运行,例如“/usr/local/bin/python3.4 'filename'”。如果您的Python版本低于2.7,则尝试升级版本并安装依赖项,然后尝试上述方法。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接