Ubuntu18.04、mecab-python3でハマりました。
Qiita初投稿です。よろしくお願い致します。
Ubuntuのデスクトップを買ったので、mecab-python3をインストールしようと思いました!
しかし、Mac OS Xのように簡単にインストールできませんでした。
sudo apt install mecab
sudo apt install libmecab-dev
sudo apt install mecab-ipadic-utf8
git clone https://github.com/neologd/mecab-ipadic-neologd.git
cd mecab-ipadic-neologd
sudo bin/install-mecab-ipadic-neologd
nano /etc/mecabrc
dicdir = /usr/lib/x86_64-linux-gnu/mecab/dic/mecab-ipadic-neologd
次にmecabをpython3で使えるようにするのですが、
sudo apt install python3-pip
sudo pip3 install mecab-python3
以下のようなエラーが出ました。
root@***:~$ sudo pip3 install mecab-python3
The directory '/home/yudai/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting mecab-python3
Downloading https://files.pythonhosted.org/packages/25/e9/bbf5fc790a2bedd96fbaf47a84afa060bfb0b3e0217e5f64b32bd4bbad69/mecab-python3-0.7.tar.gz (41kB)
100% |████████████████████████████████| 51kB 1.5MB/s
Installing collected packages: mecab-python3
Running setup.py install for mecab-python3 ... error
Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-install-v1x2vtef/mecab-python3/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-kfuoy7l5/install-record.txt --single-version-externally-managed --compile:
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
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-EKG1lX/python3.6-3.6.5=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include -I/usr/include/python3.6m -c MeCab_wrap.cxx -o build/temp.linux-x86_64-3.6/MeCab_wrap.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
MeCab_wrap.cxx:149:10: fatal error: Python.h: そのようなファイルやディレクトリはありません
include <Python.h>
^~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-install-v1x2vtef/mecab-python3/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-kfuoy7l5/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-v1x2vtef/mecab-python3/
どうしようかなと思っていると、teratailで答えてくださった方がおられました。
どうやら、Python.hというヘッダーファイルが無かった為に起こったエラーでした。
sudo apt-get install python3-dev
上記を打って再度インストールしてみると、
解決しました!
環境
uname -a
Linux hoge 4.15.0-30-generic #32-Ubuntu SMP Thu Jul 26 17:42:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
python3 -V
Python 3.6.6+