LoginSignup
36
12

More than 5 years have passed since last update.

mecab-python3(0.996.1d)のpip installでErrorとその対応方法(google colabの場合)

Posted at

@siraasagiです。
自然言語処理を中小企業経営の皆様にお役立てする為、日々勉強中です。 

0.この記事は?

2018年11月13日にmecab-python3が0.996.1にバージョンアップしました。
インストールの際に前Versionの0.7と比べて「swig」が必要になるので注意です。
私の体験談を元に問題発生から解決まで説明いたします。

1.Version up 直後に起きたError

いつものようにGoogle colabで形態素分析をする前準備をしていたその時!

install.py
!pip install mecab-python3

なんか出ましたね。おかしい...昨日まで動いていたし...

error.py
Building wheels for collected packages: mecab-python3
  Running setup.py bdist_wheel for mecab-python3 ... error
  Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-8mvddq8y/mecab-python3/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-mlhkq6i0 --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  running build_ext
  building '_MeCab' extension
  swigging MeCab.i to MeCab_wrap.cpp
  swig -python -shadow -c++ -I/usr/include -o MeCab_wrap.cpp MeCab.i
  unable to execute 'swig': No such file or directory
  error: command 'swig' failed with exit status 1

2.ログを読むとswigがfailedと書いている

この部分...そういえばswig入れていたか不安ですね。

errorPickup.py
error: command 'swig' failed with exit status 1

前処理を確認しますと...やっぱりswigが無いじゃないですか。これが原因。

apt-get.py
!apt-get -q -y install sudo file mecab libmecab-dev mecab-ipadic-utf8 git

3.対応方法「swig」をinstall

2節で紹介したapt-getの後にswigをインストールし、その後mecab-python3をインストール。

Successful.py
!apt-get -q -y install swig      # swigをインストール
!pip install mecab-python3       # mecab-python3をインストール

これでOK。私の環境はgoogle colabです。

4.pipyに書いているオフィシャルの前準備

私の前準備はなぜかpython-mecabが混入、使いませんね。
pypiのProject descriptionに書いている本家のコマンドも紹介します。

official.py
sudo apt-get install mecab mecab-ipadic-utf8 libmecab-dev swig

以上です。

36
12
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
36
12