LoginSignup
18
13

More than 5 years have passed since last update.

AWS SageMakerのノートブックインスタンスにmecabをインストールする

Last updated at Posted at 2018-07-05

概要

AWS SageMaker - AWSが提供するフルマネージドな機械学習サービス
https://aws.amazon.com/jp/blogs/news/amazon-sagemaker/

mecab - 日本語の形態素解析エンジン
http://taku910.github.io/mecab/

mecab-python3
https://pypi.org/project/mecab-python3/
https://github.com/SamuraiT/mecab-python3/blob/master/bindings.html

先月6月に東京リージョンが発表されたSageMakerですが、6月末にSageMakerを利用した機能をサービスにリリースしました。おそらく日本でもいち早く本番運用を開始したと思われます。
これから使う方々が多いかと思いますので、そのときのナレッジを共有していきます。

今回は、ノートブックインスタンスにmecabをインストールする方法です。
mecab自体は、簡単にインストールすることができるのですが、mecab-python3をインストールする際に、gccのエラーが発生しますので対応をする必要があります。

前提

・AWSアカウントを取得していて、SageMakerのノートブックインスタンスが起動している
・ノートブックインスタンスのjupyterにアクセスでき、Terminalを起動できる

結論

以下手順でインストールすることができます。

mecabのインストール

tar zxfv mecab-0.996.tar

cd mecab-0.996

./configure  --enable-utf8-only

make & make check

make install

辞書のインストール

tar zxfv mecab-ipadic-2.7.0-20070801.tar.gz

cd mecab-ipadic-2.7.0-20070801

./configure  --enable-utf8-only

make & make check

make install

mecab-python3

# gccのリンク設定(※)
sudo ln -s /usr/libexec/gcc/x86_64-amazon-linux/4.8.5/cc1plus /usr/local/bin/ 

sudo pip install mecab-python3

mecab-python3インストール時のエラー内容

$ sudo pip install mecab-python3
Collecting mecab-python==0.996

  Using cached https://files.pythonhosted.org/packages/86/e7/bfeba61fb1c5d1ddcd92bc9b9502f99f80bf71a03429a2b31218fc2d4da2/mecab-python-0.996.tar.gz

Building wheels for collected packages: mecab-python

  Running setup.py bdist_wheel for mecab-python ... error

  Complete output from command /usr/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ialYOM/mecab-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpIbdn_Spip-wheel- --python-tag cp27:

  running bdist_wheel

  running build

  running build_py

  creating build

  creating build/lib.linux-x86_64-2.7

  copying MeCab.py -> build/lib.linux-x86_64-2.7

  running build_ext

  building '_MeCab' extension

  creating build/temp.linux-x86_64-2.7

  gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2-fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/local/include -I/usr/include/python2.7 -c MeCab_wrap.cxx -o build/temp.linux-x86_64-2.7/MeCab_wrap.o

  gcc: error trying to exec 'cc1plus': execvp: No such file or directory

  error: command 'gcc' failed with exit status 1

  ----------------------------------------

  Failed building wheel for mecab-python

  Running setup.py clean for mecab-python

Failed to build mecab-python

Installing collected packages: mecab-python

  Running setup.py install for mecab-python ... error

    Complete output from command /usr/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ialYOM/mecab-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-Kqjbjt-record/install-record.txt --single-version-externally-managed --compile:

    running install

    running build

    running build_py

    creating build

    creating build/lib.linux-x86_64-2.7

    copying MeCab.py -> build/lib.linux-x86_64-2.7

    running build_ext

    building '_MeCab' extension

    creating build/temp.linux-x86_64-2.7

    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/local/include -I/usr/include/python2.7 -c MeCab_wrap.cxx -o build/temp.linux-x86_64-2.7/MeCab_wrap.o

    gcc: error trying to exec 'cc1plus': execvp: No such file or directory

    error: command 'gcc' failed with exit status 1

    ----------------------------------------

Command "/usr/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-ialYOM/mecab-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-Kqjbjt-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-ialYOM/mecab-python/

You are using pip version 9.0.1, however version 10.0.1 is available.

You should consider upgrading via the 'pip install --upgrade pip' command.

error: command 'gcc' failed with exit status 1 と表示され、 gcc部分で cc1plus がないと怒られてしまいます。

解消方法

cc1plusはインストールされていましたが、pathが独自のものでした。このモジュールが原因でしたので、/usr/local/bin/にシンボリックリンクを張って回避することができます。

sudo ln -s /usr/libexec/gcc/x86_64-amazon-linux/4.8.5/cc1plus /usr/local/bin/
sudo pip install mecab-python3
18
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
13