I couldn't find a way to use MeCab from Python3 by searching the Web, so I managed to do it myself. Here is a summary of the notes before making it available.
I was experiencing the following issues:
This can be resolved by applying two of the issues on the Google Code MeCab page. Support for Python3 is possible only by modifying mecab-python. However, if you do not fix the bug in MeCab itself, it will be buggy in parsing when used on Python. Therefore, MeCab itself is also installed and used by applying the patch and newly building it.
The URL of the patch I used had a weird token, so I wrote a link to Issue instead. Therefore, please obtain the patch at the link destination using a browser. Also, g ++ and python3-dev are required in advance.
$ wget https://mecab.googlecode.com/files/mecab-0.996.tar.gz $ tar -zxvf mecab-0.996.tar.gz $ wget request_type.patch (get at link) $ cd ~/mecab-0.996 $ patch -u < ../request_type.patch $ ./configure --enable-utf8-only $ make $ sudo make install
$ wget https://mecab.googlecode.com/files/mecab-ipadic-2.7.0-20070801.tar.gz $ tar -zxvf mecab-ipadic-2.7.0-20070801.tar.gz $ cd ~/mecab-ipadic-2.7.0-20070801 $ ./configure --with-charset=utf8 $ make $ sudo make install
$ wget https://mecab.googlecode.com/files/mecab-python-0.996.tar.gz $ tar -zxvf mecab-python-0.996.tar.gz $ wget MeCab.py (Get at link) $ wget MeCab_wrap.cxx (Get at link) $ mv MeCab.py mecab-python-0.996/ $ mv MeCab_wrap.cxx mecab-python-0.996/ $ cd ~/mecab-python-0.996 $ vi setup.py
Apply the fix for python3 (http://anond.hatelabo.jp/20121113070853) return string.split (cmd1 (str)) return Rewrite to cmd1 (str) .split ().
$ python3 setup.py build $ sudo python3 setup.py install
You cannot run mecab-python-0.996 / test.py after the installation is complete. The cause is because it is written in python2. Please check the operation after correcting it.
Recommended Posts