CentOS release 6.5 (Final) Python 2.7.6
mecab 0.996 ipadic 2.7.0
$ cd /var/tmp
$ curl -O https://mecab.googlecode.com/files/mecab-0.996.tar.gz
$ tar zxfv mecab-0.996.tar.gz
$ cd mecab-0.996
$ ./configure
$ make
$ sudo make install
$ cd /var/tmp
$ curl -O https://mecab.googlecode.com/files/mecab-ipadic-2.7.0-20070801.tar.gz
$ tar zxfv mecab-ipadic-2.7.0-20070801.tar.gz
$ cd mecab-ipadic-2.7.0-20070801
$ ./configure --with-charset=utf8
$ make
$ sudo make install
$ cd /var/tmp
$ curl -O https://mecab.googlecode.com/files/mecab-python-0.996.tar.gz
$ tar zxfv mecab-python-0.996.tar.gz
$ cd mecab-python-0.996
Modify the following files for Troubleshooting 1
$ vi setup.py
Before correction
mecab-config
Revised
/var/tmp/mecab-0.996/mecab-config
Below, the file before modification
#!/usr/bin/env python
from distutils.core import setup,Extension,os
import string
def cmd1(str):
return os.popen(str).readlines()[0][:-1]
def cmd2(str):
return string.split (cmd1(str))
setup(name = "mecab-python",
version = cmd1("mecab-config --version"),
py_modules=["MeCab"],
ext_modules = [
Extension("_MeCab",
["MeCab_wrap.cxx",],
include_dirs=cmd2("mecab-config --inc-dir"),
library_dirs=cmd2("mecab-config --libs-only-L"),
libraries=cmd2("mecab-config --libs-only-l"))
])
Corrected file
#!/usr/bin/env python
from distutils.core import setup,Extension,os
import string
def cmd1(str):
return os.popen(str).readlines()[0][:-1]
def cmd2(str):
return string.split (cmd1(str))
setup(name = "mecab-python",
version = cmd1("/var/tmp/mecab-0.996/mecab-config --version"),
py_modules=["MeCab"],
ext_modules = [
Extension("_MeCab",
["MeCab_wrap.cxx",],
include_dirs=cmd2("/var/tmp/mecab-0.996/mecab-config --inc-dir"),
library_dirs=cmd2("/var/tmp/mecab-0.996/mecab-config --libs-only-L"),
libraries=cmd2("/var/tmp/mecab-0.996/mecab-config --libs-only-l"))
])
Build python-mecab
$ python setup.py build
Install python-mecab
$ python setup.py install
Fix for Troubleshooting 2
Make sure you have libmecab.so.2.
$ ls /usr/local/lib/libmecab.so.2
/usr/local/lib/libmecab.so.2
Add / usr / local / lib
to ld.so.conf
$ vi /etc/ld.so.conf
Corrected file
ld.so.conf
include ld.so.conf.d/*.conf
/usr/local/lib
Reflect the settings in ld.so.conf
$ sudo ldconfig
run mecab-python test
$ cd /var/tmp/mecab-python-0.996
$ python test.py
Execution result
0.996
Taro noun,Proper noun,Personal name,Name,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Two nouns,number,*,*,*,*,two,D,D
Ro noun,General,*,*,*,*,Ro,Rowe,Low
Particles,Case particles,General,*,*,*,To,Wo,Wo
Verb,Independence,*,*,One step,Continuous form,to see,Mi,Mi
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
Feminine noun,General,*,*,*,*,Female,Josei,Josei
Particles,Case particles,General,*,*,*,To,D,D
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
EOS
BOS/EOS,*,*,*,*,*,*,*,*
Taro noun,Proper noun,Personal name,Name,*,*,Taro,Taro,Taro
Is a particle,Particle,*,*,*,*,Is,C,Wow
This adnominal adjective,*,*,*,*,*,this,this,this
Book noun,General,*,*,*,*,Book,Hong,Hong
Particles,Case particles,General,*,*,*,To,Wo,Wo
Two nouns,number,*,*,*,*,two,D,D
Ro noun,General,*,*,*,*,Ro,Rowe,Low
Particles,Case particles,General,*,*,*,To,Wo,Wo
Verb,Independence,*,*,One step,Continuous form,to see,Mi,Mi
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
Feminine noun,General,*,*,*,*,Female,Josei,Josei
Particles,Case particles,General,*,*,*,To,D,D
Passing verb,Independence,*,*,Godan / Sa line,Continuous form,hand over,I,I
Auxiliary verb,*,*,*,Special,Uninflected word,Ta,Ta,Ta
.. symbol,Kuten,*,*,*,*,。,。,。
BOS/EOS,*,*,*,*,*,*,*,*
EOS
EOS
filename: /usr/local/lib/mecab/dic/ipadic/sys.dic
charset: utf8
size: 392126
type: 0
lsize: 1316
rsize: 1316
version: 102
$ python setup.py build
result
$ python setup.py build
sh: mecab-config: command not found
Traceback (most recent call last):
File "setup.py", line 13, in <module>
version = cmd1("mecab-config --version"),
File "setup.py", line 7, in cmd1
return os.popen(str).readlines()[0][:-1]
IndexError: list index out of range
Reference page: Install MeCab & mecab-python Part 1
$ python test.py
result
ImportError: libmecab.so.2: cannot open shared object file: No such file or directory
Reference page: Extracting important words from Wikipedia by TF / IDF using Mecab Python
Recommended Posts