Installation and Configuration
Brooke M. Fujita edited this page Jan 4, 2018
·
4 revisions
Install natto-py as you would any other Python package:
$ pip install natto-py
This will automatically install cffi
as a dependency.
As long as the mecab
(and mecab-config
for *nix and Mac OS) executables are on your PATH
, natto-py should not require any explicit configuration.
- On *nix and Mac OS, it queries
mecab-config
to discover the path to thelibmecab.so
orlibmecab.dylib
, respectively.-
mecab-config --libs
will display the library directory and name.
-
- On Windows, it queries the Windows Registry to locate the MeCab installation folder.
- In order to convert character encodings to/from Unicode, natto-py will examine the charset of the
mecab
system dictionary.-
mecab -D
will show the system dictionary information, including file name and charset (character encoding).
-
If natto-py for some reason cannot locate the mecab
library,
or if it cannot determine the correct charset used internally by
mecab
, then you will need to set the MECAB_PATH
and MECAB_CHARSET
environment variables.
- Set the
MECAB_PATH
environment variable to the exact name/path to yourmecab
library. - Set the
MECAB_CHARSET
environment variable if you compiledmecab
and the related dictionary to use a non-default character encoding.
e.g., for Mac OS:
export MECAB_PATH=/usr/local/Cellar/mecab/0.996/lib/libmecab.dylib
export MECAB_CHARSET=utf8
e.g., for bash on UNIX/Linux:
export MECAB_PATH=/usr/local/lib/libmecab.so
export MECAB_CHARSET=euc-jp
e.g., on Windows:
set MECAB_PATH=C:\Program Files\MeCab\bin\libmecab.dll
set MECAB_CHARSET=shift-jis
e.g., from within a Python program on *nix::
import os
os.environ['MECAB_PATH']='/usr/local/lib/libmecab.so'
os.environ['MECAB_CHARSET']='utf8'