LoginSignup
8
3

More than 5 years have passed since last update.

Python3 MeCabモジュールのImportErrorの対処

Posted at

状況

いくつかの記事を参考にしてPythonからMeCabを利用するためのパッケージをインストールしたところ。

$ mecab-config --version
0.996

$ python -V
Python 3.6.1

$ pip freeze | grep mecab
mecab-python3==0.7

エラー内容

PythonからMeCabモジュールを使おうとして下記のようなImportErrorが出た:cry:

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

やったこと

共有ライブラリの探索パスを追加

$ mecab-config --libs-only-L | sudo tee /etc/ld.so.conf.d/mecab.conf
$ sudo ldconfig

なおったか試す

$ cat <<EOL | python
import MeCab
m = MeCab.Tagger ("-Ochasen")
print(m.parse ("今日もしないとね"))
EOL

出力結果

今日  キョウ   今日  名詞-副詞可能
も モ も 助詞-係助詞
し シ する  動詞-自立   サ変・スル 未然形
ない  ナイ  ない  助動詞   特殊・ナイ 基本形
と ト と 助詞-接続助詞
ね ネ ね 助詞-終助詞
EOS

うまくいったぽい:smiley:

8
3
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
8
3