The easiest way to install MeCab and ipadic on 10.9.5 and above (I'm making an assumption that "above" is true) is to use Homebrew. It's about as easy as it gets. This is in contrast to my previous instructions for 10.9.2, where lots of file editing was required. I'm also going to demonstrate how to edit MeCab's configuration file to change dictionaries.
Install MeCab via Homebrew
$ brew install mecab $ brew install mecab-ipadic
Yup, that's it. Now, to install MeCab Python 3, it's similarly ridiculously easy at this point on Mac OS.
$ pip install mecab-python3
For reference and further information, see the MeCab homepage.
Change Your MeCab Dictionary
In this example, I'll change the dictionary to the kindaigo unidic dictionary (modern, ie. Meiji period Japanese). You can find all of the NINJAL dictionaries for unidic here. To use this dictionary in Python successfully, I relied on some blog posts (Japanese only, and here's one of them), because it turns out you can't use -Ochasen option with unidic; it has to be -Owataki. See those posts for sample code.
Open file /usr/local/etc/mecabrc and change:
dicdir = /usr/local/lib/mecab/dic/ipadic dicdir = /usr/local/lib/mecab/dic/unidic
Make sure you move your preferred dictionary to the unidic directory. Just copy and paste everything that you downloaded from the NINJAL site in there, with the directory structure intact. Now, your unidic will be your default dictionary and you can use it (remember, with -Owakati as your option for parser, not -Ochasen) in MeCab Python (and also in rmecab, but as I'm not an R programmer, I won't cover that here.)
Install MeCab from source
Note that this is a legacy set of instructions from OS 10.9.2, which I'm leaving up for posterity - but this did NOT actually work for me in the end. As I feel like I need to say frequently with this software, YMMV.
First, I had to do this to make the C compiler work. This may or may not be the same for you.
sudo ln -s /usr/bin/gcc /usr/bin/gcc-apple-4.2
- Install MeCab:
- Get the MeCab source
- Switch to whatever directory you downloaded it to, then...
$ tar zxfv mecab-0.996.tar.gz $ cd mecab-0.996 $ ./configure $ make $ make check
$ tar zxfv mecab-ipadic-2.7.0-20070801.tar.gz $ cd mecab-ipadic-2.7.0-20070801 $ ./configure --with-charset=utf8
$ ./configure --with-mecab-config=~/usr/local/bin/mecab-config --prefix=~/usr/local/bin --with-charset=utf8(This actually didn't work for me. I ended up using Homebrew to install instead.
$ make $ sudo make install
$ mecab test test 名詞,固有名詞,組織,*,*,*,* EOSIf you get this output, you have successfully installed MeCab on your Mac.