Scikit-学习不正确构建

时间:2017-01-24 07:22:20

标签: python scikit-learn

这是我第一次尝试在任何系统上安装python。

我已遵循指南: http://scikit-learn.org/stable/developers/advanced_installation.html

并安装了所有构建依赖项。然后我使用pip安装: pip install scikit-learn

使用pip安装时没有错误。

当我尝试运行我的预测程序时,我的环境在cloud9上工作正常,我收到此错误:

root@ubuntu-512mb-sfo1-01-PredictionAPI:~/api-for-ml-requests/api# Traceback (most recent call last):
    from sklearn.feature_extraction.text import CountVectorizer
  File "/usr/local/lib/python2.7/dist-packages/sklearn/__init__.py", line 56, in <module>
    from . import __check_build
  File "/usr/local/lib/python2.7/dist-packages/sklearn/__check_build/__init__.py", line 46, in <module>
    raise_build_error(e)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/__check_build/__init__.py", line 41, in raise_build_error
-bash: syntax error near unexpected token `most'
root@ubuntu-512mb-sfo1-01-PredictionAPI:~/api-for-ml-requests/api#   File "Backend-Rest-Alpha.1.py", line 9, in <module>
-bash: syntax error near unexpected token `newline'
root@ubuntu-512mb-sfo1-01-PredictionAPI:~/api-for-ml-requests/api#     from backend.Predictions import predict
from: can't read /var/mail/backend.Predictions
root@ubuntu-512mb-sfo1-01-PredictionAPI:~/api-for-ml-requests/api#   File "/root/api-for-ml-requests/api/backend/Predictions.py", line 1, in <module>
-bash: syntax error near unexpected token `newline'
root@ubuntu-512mb-sfo1-01-PredictionAPI:~/api-for-ml-requests/api#     from sklearn.feature_extraction.text import CountVectorizer
from: can't read /var/mail/sklearn.feature_extraction.text
root@ubuntu-512mb-sfo1-01-PredictionAPI:~/api-for-ml-requests/api#   File "/usr/local/lib/python2.7/dist-packages/sklearn/__init__.py", line 56, in <module>
-bash: syntax error near unexpected token `newline'
root@ubuntu-512mb-sfo1-01-PredictionAPI:~/api-for-ml-requests/api#     from . import __check_build
root@ubuntu-512mb-sfo1-01-PredictionAPI:~/api-for-ml-requests/api#   File "/usr/local/lib/python2.7/dist-packages/sklearn/__check_build/__init__.py", line 46, in <module>
-bash: syntax error near unexpected token `newline'
root@ubuntu-512mb-sfo1-01-PredictionAPI:~/api-for-ml-requests/api#     raise_build_error(e)
-bash: syntax error near unexpected token `e'
root@ubuntu-512mb-sfo1-01-PredictionAPI:~/api-for-ml-requests/api#   File "/usr/local/lib/python2.7/dist-packages/sklearn/__check_build/__init__.py", line 41, in raise_build_error
    %s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
ImportError: /usr/local/lib/python2.7/dist-packages/sklearn/__check_build/_check_build.so: undefined symbol: PyUnicodeUCS4_DecodeUTF8
___________________________________________________________________________
Contents of /usr/local/lib/python2.7/dist-packages/sklearn/__check_build:
__init__.py               setup.py                  setup.pyc
_check_build.so           __init__.pyc
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.

有没有人知道可能导致这种情况的原因?

2 个答案:

答案 0 :(得分:1)

看起来您的模块是使用USC4编码在python上构建的,而您的python正在使用USC2。

来自python documentation

  

Python是使用2字节Unicode字符构建的,扩展模块是使用具有4字节Unicode字符的Python编译的。

     

使用预建的扩展程序包时很容易发生这种情况。

     

解决此问题的唯一方法是使用扩展模块   使用相同大小的Unicode构建的Python二进制文件编译   字符。

您应该尝试从源代码安装软件包。您在问题中提供的链接中描述了sklearn的操作方法 - 对于scipy套件,您可以找到说明here。如果你不使用mac,那个页面右上方菜单上的链接也会显示windows和linux的指南。

答案 1 :(得分:0)

由于您不熟悉,我建议您安装https://www.continuum.io/downloads#linux 它将解决您的问题,因为它包含scikit-learn和python以及所有依赖项以及在Python中用于各种任务的长列表库。另外,我建议你使用PyCharm Community Edition作为IDE,你可以轻松添加你需要的任何类型的库,而不用担心。 https://www.jetbrains.com/pycharm/