【问题标题】:trouble importing skllearn导入sklearn的麻烦
【发布时间】:2014-06-28 06:32:57
【问题描述】:

您好,我已经安装了 Scikit-learn,但是当我尝试导入 sklearn 模块时,我不断收到错误消息。它显示以下味精。有谁知道发生了什么?

import sklearn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sklearn/__init__.py", line 31, in <module>
    from . import __check_build
  File "sklearn/__check_build/__init__.py", line 46, in <module>
    raise_build_error(e)
  File "sklearn/__check_build/__init__.py", line 41, in raise_build_error
    %s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
ImportError: No module named _check_build
___________________________________________________________________________
Contents of sklearn/__check_build:
__init__.py               __init__.pyc              _check_build.c
_check_build.pyx          setup.py                  setup.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.

【问题讨论】:

  • 你是怎么安装的?你的操作系统是什么?
  • 在雪豹 cd、gfortran、numpy 1.8 和 scipy 中安装 xcode 后,在 osx 10.6.8 中运行 setup.py 脚本。
  • 我已经通过 apt-get 尝试过,它工作正常。你在系统中安装了python-dev 包吗?
  • 我不这么认为。我使用的是预安装的 python 版本,但我改为 2.7 版本。 python-dev包是什么?
  • python-dev 包将安装许多 C 头文件,例如 python.h,许多包已经用 C 编写,python 可以使用它们。

标签: python-2.7 scikit-learn


【解决方案1】:

正如您在错误中看到的那样:ImportError: No module named _check_build 在该目录中它有 .c 文件并且它从未编译过。

如果您检查this link,您会看到scikit-learn 的许多部分是用C 编写的。

所以要安装这种包,你需要在你的系统中安装python-dev包。

python-dev 包将安装许多 C 头文件,例如 python.h

所以在您的系统中安装python-dev 包,然后删除并再次安装scikit-learn 包。

【讨论】:

    猜你喜欢
    • 2017-04-10
    • 2012-08-23
    • 2018-10-29
    • 1970-01-01
    • 2020-12-23
    • 2019-09-17
    • 2023-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多