安装scikit-learn python3时出错

问题描述 投票:1回答:1

所以我能够为python2安装sklearn,但出于某种原因我遇到了为python3做同样的问题。我收到此错误:

Traceback (most recent call last):
  File "/home/ajshack_pg/sklearn/__check_build/__init__.py", line 44, in <module>
    from ._check_build import check_build  # noqa
ImportError: /home/ajshack_pg/sklearn/__check_build/_check_build.so: undefined symbol: PyUnicodeUCS4_DecodeUTF8

During handling of the above exception, another exception occurred:

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

我试图进入源目录并键入他们所说的无济于事。有什么见解吗?

谢谢!

python python-3.x scikit-learn install
1个回答
1
投票

如果您从Python 2.x的源代码安装了sklearn,则如果您没有完全删除所有sklearn文件,则其某些二进制文件可能会保留。 Python 2.x和3.x彼此完全不兼容,因此这可能是它无法构建的原因。

采取的几个步骤:

  1. 考虑为你的sklearn项目使用virtualenv,特别是如果你有很多不同的包或Python版本。它非常适合保持不同的开发环境,使用不同的Python包和库。如果你还没有它,请关注this guide。创建virtualenv时,请确保在创建virtualenv时使用此命令安装Python 3.x: virtualenv -p python3 envname
  2. 如果从源代码构建:重新下载Python 3版本的sklearn源代码并将其放在virtualenv中。严格遵循所有构建说明。这应该有希望给你一个干净的sklearn安装。
  3. 如果用pip安装:激活你的virtualenv,那么:pip install -U scikit-learn安装numpyscipy之后。
© www.soinside.com 2019 - 2024. All rights reserved.