所以我能够为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.
我试图进入源目录并键入他们所说的内容无济于事。有什么见解吗?
谢谢!
答案 0 :(得分:1)
如果您从Python 2.x的源代码安装了sklearn,则如果您没有完全删除所有sklearn文件,则其某些二进制文件可能会保留。 Python 2.x和3.x彼此完全不兼容,因此这可能是它无法构建的原因。
采取以下几个步骤:
考虑对你的sklearn项目使用virtualenv,特别是如果你有很多不同的包或Python版本。它非常适合保持不同的开发环境,使用不同的Python包和库。如果您还没有,请关注this guide。在创建virtualenv时,请确保在创建virtualenv时使用此命令使用Python 3.x安装它:
virtualenv -p python3 envname
如果从源代码构建:重新下载Python 3版本的sklearn源代码并将其放在virtualenv中。严格遵循所有构建说明。这应该有希望给你一个干净的sklearn安装。
如果使用pip安装:激活您的virtualenv,则:
安装pip install -U scikit-learn
和numpy
。
scipy
醇>