Install mecab-python on CentOS

Verification environment

CentOS release 6.5 (Final) Python 2.7.6

Installation

mecab 0.996 ipadic 2.7.0

install meacb

$ 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

ipadic installation

$ 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

install mecab-python

$ 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

test

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

trouble shooting

Troubleshooting 1

$ 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

Troubleshooting 2

$ 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

Install mecab-python on CentOS
Install Faiss on CentOS 7
Install numba on CentOS 7.2
Install Python3.4 on CentOS 6.6
Install Python 2.7.3 on CentOS 5.4
Install awscli on centos7
Install Chainer on CentOS 6.7
Install mecab-python on Mac
Install ImageMagick-6.2.x series on CentOS7.7
Install Python 3.8 on CentOS 7 (SCL)
Install Chrome on CentOS 7 series
Install Python 3.8 on CentOS 8 (AppStream)
Steps to install MySQL 8.0 on CentOS 8.1
Install Mecab and mecab-python3 on Ubuntu 14.04
Steps to install VirtualBox on CentOS
Install java (Oracle JDK14) on CentOS7
How to install PyPy on CentOS
How to install TensorFlow on CentOS 7
Install pip on CentOS7. Also iPython.
Install VirtualBox on CentOS 7 on VirtualBox (mac + vagrant)
Install Python on CentOS using Pyenv
How to install Maven on CentOS
Study Note 9_Install Jenkins on CentOS7
Install Python on CentOS using pyenv
CentOS8 --Install --Django
CentOS8 --Install --Python3
Enable sar command on CentOS (install sysstat)
How to install Apache (httpd) on CentOS7
How to install Eclipse GlassFish 5.1.0 on CentOS 7
How to install Apache (httpd) on CentOS8
Install PostgreSQL from source code on CentOS
Install pyenv and rbenv on CentOS system-wide
Install mecab on Marvericks
Install Tensorflow on Mac
Install TensorFlow on Ubuntu
Install python on WSL
Install pyenv on mac
Install pip on Mavericks
Install Python on Pidora.
Install Scrapy on python3
Install Ansible on Mac
[Ansible] Install dnf on Centos7 with Python3 interpreter
Install Python 3 on Mac
Install PySide2 on Ubuntu
Install gensim on Marvericks
Install JModelica on Ubuntu
Install Anaconda on Windows 10
Install numpy on Marvericks
Install python on windows
Install enebular-agent on Chromebook
Install pycuda on Windows10
Install aws-cli on MacPorts
Install pygraphviz on Windows 10
Install Docker on AWS
Install Python 3.3 on Ubuntu 12.04
[Failure] Install Stack Overflow Clone Askbot on CentOS 6.4
Install Chainer 1.5.0 on Windows
Install Python 3.4 on Mac
Installation on CentOS8 VirtualBox
Install Caffe on Mac
Install Theano on Ubuntu 12.04