Jimmy
Jimmy

Reputation: 85

Scikit-learn not being built properly

This is my first time trying to install python on any system.

I have followed the guide on: http://scikit-learn.org/stable/developers/advanced_installation.html

and installed all build dependencies. I then installed using pip: pip install scikit-learn

I had no errors when installing with pip.

When I try to run my prediction program, which works fine on my environment on cloud9, I get this error:

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.

Does anyone have an idea as to what could be causing this?

Upvotes: 1

Views: 801

Answers (2)

id5h
id5h

Reputation: 205

It seems like your module was built on a python using USC4 encoding, while your python is using USC2.

From the python documentation:

Python was built using 2-byte Unicode characters, and the extension module was compiled using a Python with 4-byte Unicode characters.

This can easily occur when using pre-built extension packages.

The only way to solve this problem is to use extension modules compiled with a Python binary built using the same size for Unicode characters.

You should try to install the packages from source. The how-to for sklearn is described in the link you provided with your question - and for the scipy suite you can find instruction here. If you're not using a mac, the links on the top-right menu on that page show the guides for windows and linux as well.

Upvotes: 1

Sulaiman Khan
Sulaiman Khan

Reputation: 908

As you are new to this, I suggest you to install https://www.continuum.io/downloads#linux It will solve you problem as it contains scikit-learn and python and all dependencies and also a long list libraries which are used in Python for various task. Also i suggest you to use PyCharm Community Edition as IDE where you can add easily any kind of library you needed without feeling any worry. https://www.jetbrains.com/pycharm/

Upvotes: 0

Related Questions