Skip to main content

Python wrapper for the MeCab morphological analyzer for Japanese

Project description

This is a Python wrapper for the MeCab morphological analyzer for Japanese text. It works with Python 3.6 and greater; if you need to use Python 2.7, use v1.0.2.

Note: If using MacOS Big Sur, you'll need to upgrade pip to version 20.3 or higher to use wheels due to a pip issue.

issueを英語で書く必要はありません。

Note that Windows wheels require a Microsoft Visual C++ Redistributable, so be sure to install that.

Basic usage

>>> import MeCab
>>> wakati = MeCab.Tagger("-Owakati")
>>> wakati.parse("pythonが大好きです").split()
['python', 'が', '大好き', 'です']

>>> tagger = MeCab.Tagger()
>>> print(tagger.parse("pythonが大好きです"))
python  python  python  python  名詞-普通名詞-一般
                        助詞-格助詞
大好き  ダイスキ        ダイスキ        大好き  形状詞-一般
です    デス    デス    です    助動詞  助動詞-デス     終止形-一般
EOS

The API for mecab-python3 closely follows the API for MeCab itself, even when this makes it not very “Pythonic.” Please consult the official MeCab documentation for more information.

Installation

Binary wheels are available for MacOS X, Linux, and Windows (64bit) are installed by default when you use pip:

pip install mecab-python3

These wheels include an internal (statically linked) copy of the MeCab library, but not dictionary. In order to use MeCab you'll need to install a dictionary. unidic-lite is a good one to start with:

pip install unidic-lite

To build from source using pip,

pip install --no-binary :all: mecab-python3

Dictionaries

There are many different dictionaries available for MeCab. These UniDic packages, which include slight modifications for ease of use, are recommended:

  • unidic: The full UniDic 2.3.0.
  • unidic-lite: The older, much smaller, but not much less useful 2.1.2.

The dictionaries below are not recommended due to being unmaintained for many years, but they are available for use with legacy applications.

For more details on the differences between dictionaries see here.

Common Issues

If you get a RuntimeError when you try to run MeCab, here are some things to check:

Windows Redistributable

You have to install this to use this package on Windows.

Installing a Dictionary

Run pip install unidic-lite and confirm that works. If that fixes your problem, you either don't have a dictionary installed, or you need to specify your dictionary path like this:

tagger = MeCab.Tagger('-r /dev/null -d /usr/local/lib/mecab/dic/mydic')

Note: on Windows, use nul instead of /dev/null. Alternately, if you have a mecabrc you can use the path after -r.

Specifying a mecabrc

If you get this error:

error message: [ifs] no such file or directory: /usr/local/etc/mecabrc

You need to specify a mecabrc file. It's OK to specify an empty file, it just has to exist. You can specify a mecabrc with -r. This may be necessary on Debian or Ubuntu, where the mecabrc is in /etc/mecabrc.

You can specify an empty mecabrc like this:

tagger = MeCab.Tagger('-r/dev/null -d/home/hoge/mydic')

Using Unsupported Output Modes like -Ochasen

Chasen output is not a built-in feature of MeCab, you must specify it in your dicrc or mecabrc. Notably, Unidic does not include Chasen output format. Please see the MeCab documentation.

Alternatives

  • fugashi is a Cython wrapper for MeCab with a Pythonic interface, by the current maintainer of this library
  • SudachiPy is a modern tokenizer with a maintained dictionary, though it's slower than MeCab
  • KoNLPy is a library for Korean NLP that includes a MeCab wrapper

Licensing

Like MeCab itself, mecab-python3 is copyrighted free software by Taku Kudo taku@chasen.org and Nippon Telegraph and Telephone Corporation, and is distributed under a 3-clause BSD license (see the file BSD). Alternatively, it may be redistributed under the terms of the GNU General Public License, version 2 (see the file GPL) or the GNU Lesser General Public License, version 2.1 (see the file LGPL).

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mecab_python3-1.0.4a1-cp39-cp39-win_amd64.whl (510.4 kB view details)

Uploaded CPython 3.9Windows x86-64

mecab_python3-1.0.4a1-cp39-cp39-macosx_10_14_x86_64.whl (280.8 kB view details)

Uploaded CPython 3.9macOS 10.14+ x86-64

mecab_python3-1.0.4a1-cp38-cp38-win_amd64.whl (510.5 kB view details)

Uploaded CPython 3.8Windows x86-64

mecab_python3-1.0.4a1-cp38-cp38-macosx_10_14_x86_64.whl (281.0 kB view details)

Uploaded CPython 3.8macOS 10.14+ x86-64

mecab_python3-1.0.4a1-cp37-cp37m-win_amd64.whl (510.2 kB view details)

Uploaded CPython 3.7mWindows x86-64

mecab_python3-1.0.4a1-cp37-cp37m-macosx_10_14_x86_64.whl (280.9 kB view details)

Uploaded CPython 3.7mmacOS 10.14+ x86-64

mecab_python3-1.0.4a1-cp36-cp36m-macosx_10_14_x86_64.whl (280.8 kB view details)

Uploaded CPython 3.6mmacOS 10.14+ x86-64

File details

Details for the file mecab_python3-1.0.4a1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: mecab_python3-1.0.4a1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 510.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for mecab_python3-1.0.4a1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 7ee7a6ef5dee0164877d3509dbee72c35667abbc92d6ebd4c401822dc9c4cd60
MD5 6afe724f60dccdbacf2270be9a7132fc
BLAKE2b-256 8d5abd5b8c43f7f38e6345326935b1e93c6ab9126a69dea75a4fdd115203570a

See more details on using hashes here.

File details

Details for the file mecab_python3-1.0.4a1-cp39-cp39-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: mecab_python3-1.0.4a1-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 280.8 kB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for mecab_python3-1.0.4a1-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 074f69f1201b152fcad02f13297ceba1c23f94dc9008664dca266e8da507f1ea
MD5 65ebf9a226f8b5ececc22ad045cc5dc7
BLAKE2b-256 07afc93cdfabcd6f2d162ab2c12358a9ce87940845a136e38a1c364661dae507

See more details on using hashes here.

File details

Details for the file mecab_python3-1.0.4a1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: mecab_python3-1.0.4a1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 510.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for mecab_python3-1.0.4a1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 431a4fdd03830d9f7524dbf3f6ee779ebe74444fe4ab453831b50571332f2219
MD5 84a571637ca8806662bc19c8adbe20dc
BLAKE2b-256 f99c6a8d2fddcdf6d1564c0ca5e1d6750b256db970c33f57529bf6a9afd032f7

See more details on using hashes here.

File details

Details for the file mecab_python3-1.0.4a1-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: mecab_python3-1.0.4a1-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 281.0 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.10

File hashes

Hashes for mecab_python3-1.0.4a1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 c9b8e1a4033a87565a054b1798d897f9baee2412dd2a77d3c337d66fbea623c7
MD5 6fa2833ae5043d404c1eecf08577fc53
BLAKE2b-256 afde3e7181c0e3f8ec71c339be0e1a033238d764fa4ddb18bdc3e4823f095172

See more details on using hashes here.

File details

Details for the file mecab_python3-1.0.4a1-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: mecab_python3-1.0.4a1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 510.2 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.9

File hashes

Hashes for mecab_python3-1.0.4a1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 b0087180cddbc55000d1daf8ecfed92c8e5a06ca84fd9c53647427fd79755f94
MD5 58fec16ebab19d139f532366390e67b9
BLAKE2b-256 3c2b51438e28aaa7c044ebde179c60ef7d10c8588fbf5e049c27bdd456c9efbc

See more details on using hashes here.

File details

Details for the file mecab_python3-1.0.4a1-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: mecab_python3-1.0.4a1-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 280.9 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10

File hashes

Hashes for mecab_python3-1.0.4a1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 c4b2f0ac43835c87f807456ab6076925f093318abd497d49f4362779ccfdf651
MD5 659b43ce14698ddd4059d75f7baeb799
BLAKE2b-256 64b9a89d9afa5d83cea4bdc330daee98e6ce087332236052e77efc3bee91ee09

See more details on using hashes here.

File details

Details for the file mecab_python3-1.0.4a1-cp36-cp36m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: mecab_python3-1.0.4a1-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 280.8 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.13

File hashes

Hashes for mecab_python3-1.0.4a1-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 d2541b9864b31d899fc4cf019857de5eea97e8cf16c3c459b64a6bd317556e6a
MD5 15c68884946f64e06a9585a1e6482f2f
BLAKE2b-256 72307b82b6779e69e83f40f89b4dd0395a6e8076b4cbb8f273b54ff2b16d189e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page