Skip to content

Instantly share code, notes, and snippets.

@YoshihitoAso
Last active December 18, 2018 05:30
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YoshihitoAso/9048005 to your computer and use it in GitHub Desktop.
Save YoshihitoAso/9048005 to your computer and use it in GitHub Desktop.
[Python][Mecab]ubuntu環境にmecabをインストールする方法

Ubuntu環境にMecabをインストールする方法

インストール手順

$ sudo apt-get install mecab libmecab-dev mecab-ipadic
$ sudo aptitude install mecab-ipadic-utf8
$ sudo apt-get install python-mecab

SAMPLE

mecab_sample.py

# coding: utf-8
import sys
import MeCab

m = MeCab.Tagger ("-Ochasen")

print ("私の名前はボブです。")
print m.parse("私の名前はボブです。")

↓↓実行結果↓↓

私の名前はボブです。
私      ワタシ  私      名詞-代名詞-一般
の      ノ      の      助詞-連体化
名前    ナマエ  名前    名詞-一般
は      ハ      は      助詞-係助詞
ボブ    ボブ    ボブ    名詞-固有名詞-人名-名
です    デス    です    助動詞  特殊・デス      基本形
。      。      。      記号-句点
EOS
@tony7302y2k
Copy link

tony7302y2k commented Sep 20, 2016

環境: Ubuntu:14.04, python:Python 2.7.6
Sorry, I following this website of content. However, my compliers always show me this error below as:
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import sys
import MeCab
MeCab.Tagger ("-Ochasen")
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/MeCab.py", line 307, in init
this = _MeCab.new_Tagger(*args)
RuntimeError

Can you tell me why and how to fix it? Thank you very much.

@shekharkoirala
Copy link

is the answer available ?

@shekharkoirala
Copy link

Download , mecab-ipdaic-neologd dictionary

git clone --depth 1 https://github.com/neologd/mecab-ipadic-neologd.git
cd mecab-ipadic-neologd
./bin/install-mecab-ipadic-neologd -n
echo mecab-config --dicdir"/mecab-ipadic-neologd"

/usr/local/lib/mecab/dic/mecab-ipadic-neologd

Other than this is confirmation of not proper path of dictionary.
mecab -D
Here is my error , the dict is in another path.
Error: param.cpp(69) [ifs] no such file or directory: /usr/local/lib/mecab/dic/ipadic/dicrc

But this is working :
echo "8月3日に放送された「中居正広の金曜日のスマイルたちへ」(TBS系)で、1日たった5分でぽっこりおなかを解消するというダイエット方法を紹介。キンタロー。のダイエットにも密着。" | mecab -d /usr/local/lib/mecab/dic/mecab-ipadic-neologd

Reason is , the path is working.
So Final step :
locate mecabrc
dicdir = /usr/local/lib/mecab/dic/mecab-ipadic-neologd

To every file found, replace the value of dicdir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment