自然言語処理ブログ

自然言語処理をマーケティングに役立てたいブログです

さくらVPSのcentos6にfasttextをインストールする

タイトルの通りなのですが、少しはまりました。

インストールしたサーバーはcentos6をインストールして特に設定をしてないサーバーです。

 

手順としては

git clone 

make

easy_install cython

pip install fasttext

 

の4手順でインストールできるみたい。カンタン☆

makeではまる

oh...

fasttextをgitでcloneしてmakeすると・・・

src/dictionary.cc: In member function ‘void Dictionary::threshold(int64_t)’:
src/dictionary.cc:195: error: expected primary-expression before ‘[’ token

...

こんなエラーがでます。なんだろうと調べると、どうやらgccのバージョンが古いことが原因っぽい。gccを4.4から4.8にバージョンアップする必要があるようです。

CentOSに新しいバージョンのGCC/G++(4.8/4.9)をインストールする - TASK NOTES

こちらを参考にして、gccをバージョンアップ

easy_install cythonではまる

opps!!

easy_installでエラー・・・

Running Cython-0.24.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-tY01Iv/Cython-0.24.1/egg-dist-tmp-yiqhrx

Unable to find pgen, not compiling formal grammar.
warning: no files found matching '*.pyx' under directory 'Cython/Debugger/Tests'
warning: no files found matching '*.pxd' under directory 'Cython/Debugger/Tests'
warning: no files found matching '*.h' under directory 'Cython/Debugger/Tests'
warning: no files found matching '*.pxd' under directory 'Cython/Utility'
/tmp/easy_install-tY01Iv/Cython-0.24.1/Cython/Plex/Scanners.c:4:20: fatal error: Python.h: そのようなファイルやディレクトリはありません
#include "Python.h"

...

こんなエラーがでます。これはいろいろ調べると、python-develが入ってない事が原因っぽい。なので、yum install python-devel をインストール。

pip install fasttextではまる

わーお

今度は、

gcc: error: fasttext/fasttext.c: そのようなファイルやディレクトリはありません

gcc: fatal error: no input files
compilation terminated.
error: command 'gcc' failed with exit status 4 

こんなエラー

こちらはいくら探しても解決できず、、pythonのバージョンをサーバーのデフォルトでインストールしてるのですが、それが原因じゃないかと推測。どうやらpyenvを利用するのが良さそうです。

pyenvをインストールする

pyenvはpythonのバージョン管理を簡単にやってくれるものらしい。

http://uorat.hatenablog.com/entry/2016/02/03/131534

こちらを参考にするとpyenvのインストールはサクっとおわります。

python2.7.11をインストールするpyenvで

vpsのデフォルトは2.6のため、2.7.11をインストールします。pyenv install 2.7.11でインストールできます。時間が少しかかるけど・・・

と思ったらまたエラー

-> https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tar.xz
Installing Python-2.7.11...
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
ERROR: The Python zlib extension was not compiled. Missing the zlib?

Please consult to the Wiki page to fix the problem.
https://github.com/yyuu/pyenv/wiki/Common-build-problems

ummm...

指示通り下記をみると

https://github.com/yyuu/pyenv/wiki/Common-build-problems

 いろいろインストールしてねと書いてあります(cent osのところ)

まだでるエラー

pyenv global 2.7.11

pythonを切替て、pip install fasttextすると・・・

error!!!!

You are using pip version 7.1.2, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

pipのバージョン上げてねと言われる。さっきまで8.1.2だった気がするけど、pyenvで切り替えたからかな。

pip install --upgrade pip すると8.1.2にアップグレードされます。

最後のエラー

今度こそと思い、pip install fasttext すると・・・

エラー

    ImportError: No module named Cython.Build

むむむ。cythonがどっか行っちゃったのかな。

再び、pip install cython でインストール。

ついにfastTextをinstall

上記を経て

install fasttext
Collecting fasttext
Using cached fasttext-0.7.6.tar.gz
Collecting numpy>=1 (from fasttext)
Downloading numpy-1.11.1-cp27-cp27mu-manylinux1_x86_64.whl (15.3MB)
100% |████████████████████████████████| 15.3MB 36kB/s
Collecting future (from fasttext)
Using cached future-0.15.2.tar.gz
Installing collected packages: numpy, future, fasttext
Running setup.py install for future ... done
Running setup.py install for fasttext ... done
Successfully installed fasttext-0.7.6 future-0.15.2 numpy-1.11.1

SUCCESS!!!!

いやー大変でした。

これから、形態素解析です。

 

fin.