5
4

More than 5 years have passed since last update.

pip installでmecab-python3が失敗する

Posted at

問題

pip install mecab-python3をすると、

    ~なんかいろいろ~
    Complete output (10 lines):
    /bin/sh: 1: mecab-config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-lgnju1hb/mecab-python3/setup.py", line 41, in <module>
        include_dirs=cmd2("mecab-config --inc-dir"),
      File "/tmp/pip-install-lgnju1hb/mecab-python3/setup.py", line 21, in cmd2
        return cmd1(strings).split()
      File "/tmp/pip-install-lgnju1hb/mecab-python3/setup.py", line 18, in cmd1
        return os.popen(strings).readlines()[0][:-1]
    IndexError: list index out of range
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

というログが出てきて、インストールできない。

環境とか

VagrantのDebian9 (Windows10 Pro上)
ただし、cat /etc/os-releaseをするとPRETTY_NAME="Debian GNU/Linux 10 (buster)"とでる。
これはパッケージリストを間違ってbusterを使う設定にしてしまったので、特に気にしない。

(注意) 一度この記事をすべて読み進めてみてから実行してみることをおすすめします。

一部不安定や確立しない場合がありますので、それらを考慮しつつ実行してください。
責任は一切負いませんので、不安な方はバックアップをとるなりしてから実行してください。
殴り書きです。

解決方法

少し長いです。
上から2行目あたりで、/bin/sh: 1: mecab-config: not foundと言われてるので、ターミナル上でmecab-configと打ってみると、
->zsh: command not found: mecab-config
とでるので、sudo apt install libmecab-devと打ってlibmecab-devをインストールする。

またpip install mecab-python3をやってみると、

Complete output (12 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    copying MeCab.py -> build/lib.linux-x86_64-3.6
    running build_ext
    building '_MeCab' extension
    creating build/temp.linux-x86_64-3.6
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/include -I/home/vagrant/.pyenv/versions/3.6.5/envs/topics/include -I/home/vagrant/.pyenv/versions/3.6.5/include/python3.6m
-c MeCab_wrap.cxx -o build/temp.linux-x86_64-3.6/MeCab_wrap.o
    gcc: error trying to exec 'cc1plus': execvp: No such file or directory
    error: command 'gcc' failed with exit status 1
    ----------------------------------------

というエラーが出る。gcc: error trying to exec 'cc1plus': execvp: No such file or directoryとかわけのわからんこと言ってるので、ググるとgccとg++のバージョンが同じじゃないとだめらしいとわかった。ので、確認してみる:

❯ gcc --version
gcc (Debian 8.3.0-6) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

❯ g++ --version
g++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

まあバージョン合ってないので、調整する。
g++のほうが遅れているようなので、sudo apt remove g++ g++-6しちゃって、

❯ g++ -v
zsh: command not found: g++

となるのを確認してから、sudo apt install g++ g++-8を実行する。
そのあと、バージョン確認をしてみる:

topics ❯ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
~いろいろ~
gcc version 8.3.0 (Debian 8.3.0-6)

おそらく、gcc -vをしても同様の結果が得られるはず。
あとは、pip install mecab-python3をして、インストール完了。

5
4
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
5
4