あおのたすのブログ

Deep Learningと自然言語処理と機械学習に興味がある大学院生のブログ。最近は強化学習・Semi-Supervisedなどに興味が出てきた。

PythonでMecabを使ってみる

PythonMeCabをインストールしてみます。

 

// mecab本体

$ wget http://mecab.googlecode.com/files/mecab-0.99.tar.gz

$ tar -xzf mecab-0.99.tar.gz

$ cd mecab-0.99

$ ./configure --with-charset=utf8

$ make && sudo make install

 

// mecab-ipadic

$ wget http://sourceforge.net/projects/mecab/files/mecab-ipadic/2.7.0-20070801/mecab-ipadic-2.7.0-20070801.tar.gz/download

//$ tar -xzf mecab-ipadic-2.7.0-20070801.tar.gz

$ tar -xzf download

$ cd mecab-ipadic-2.7.0-20070801

$ ./configure --with-charset=utf8

$ make && sudo make install

 

// mecab-python

$ wget http://mecab.googlecode.com/files/mecab-python-0.993.tar.gz

$ tar -xzf mecab-python-0.993.tar.gz

$ cd mecab-python-0.993

$ python setup.py build

$ sudo python setup.py install

 

 

それでpython

import MeCab

を実行してみたのだけれども。。。エラー。

 

>>> import MeCab

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "MeCab.py", line 25, in <module>

    _MeCab = swig_import_helper()

  File "MeCab.py", line 17, in swig_import_helper

    import _MeCab

ImportError: libmecab.so.2: cannot open shared object file: No such file or directory

 

 

そこで、

vim /etc/ld.so.confを実行して

/usr/local/lib 

を追加する。

 

 ldconfig 

で更新して、

 

Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18) 

[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>> import MeCab

>>> 

 

無事インストールできました。