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, as well as Python 2.7.

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

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 libray
  • 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.3a1-cp39-cp39-macosx_10_14_x86_64.whl (280.5 kB view details)

Uploaded CPython 3.9macOS 10.14+ x86-64

mecab_python3-1.0.3a1-cp38-cp38-macosx_10_14_x86_64.whl (280.7 kB view details)

Uploaded CPython 3.8macOS 10.14+ x86-64

mecab_python3-1.0.3a1-cp37-cp37m-macosx_10_14_x86_64.whl (280.5 kB view details)

Uploaded CPython 3.7mmacOS 10.14+ x86-64

mecab_python3-1.0.3a1-cp36-cp36m-macosx_10_14_x86_64.whl (280.5 kB view details)

Uploaded CPython 3.6mmacOS 10.14+ x86-64

mecab_python3-1.0.3a1-cp35-cp35m-macosx_10_14_x86_64.whl (280.5 kB view details)

Uploaded CPython 3.5mmacOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: mecab_python3-1.0.3a1-cp39-cp39-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 280.5 kB
  • Tags: CPython 3.9, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

File hashes

Hashes for mecab_python3-1.0.3a1-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 76d4c0643fe2eea3bff65faf4769ec6d9fe69a12277d949285f11d3eee287c10
MD5 00f3260876cc653b5513150e914822fe
BLAKE2b-256 db055e5092d65a343f52212c8cc32422c8c3b2def587b3448806085ff9993ea3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mecab_python3-1.0.3a1-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 280.7 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for mecab_python3-1.0.3a1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 5400ae0c4a70709b6b7b099bf9bf0dfc621f3249756a10e7c02a54698dd51fcb
MD5 f50f479609206d25d87e239d5c97a77f
BLAKE2b-256 a378f86cc74dc910ea918f14f1e0173bbde46c94b04f0e74f4e2c8c8313f47be

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mecab_python3-1.0.3a1-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 280.5 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.9

File hashes

Hashes for mecab_python3-1.0.3a1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 0b140b3f86ab3faad311a2848a2e3fc55a64110e1d827d6decaed26c11d6943e
MD5 6a2a68bde696dee71c5a16c3dbf6d827
BLAKE2b-256 1e0ffa274e12b7db79d0bf2fa2f187517c20194b911536be2065836b4f52a4e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mecab_python3-1.0.3a1-cp36-cp36m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 280.5 kB
  • Tags: CPython 3.6m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.12

File hashes

Hashes for mecab_python3-1.0.3a1-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 edae983664d4bb031bd9027d8b3654070db63b796f707de4b4a74bcd80b2d23d
MD5 62deca99ac363c27432ffdcb474ad157
BLAKE2b-256 b4f85ed4d86bfeb22ba692db9fe8c3532538993099996970d8519f2e7592139c

See more details on using hashes here.

File details

Details for the file mecab_python3-1.0.3a1-cp35-cp35m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: mecab_python3-1.0.3a1-cp35-cp35m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 280.5 kB
  • Tags: CPython 3.5m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.5.10

File hashes

Hashes for mecab_python3-1.0.3a1-cp35-cp35m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 4a2dfaf69c67dd7f76fef1a1084a725a6510ca5f72c5f0110c791fc5b9c57ad9
MD5 e3dc3dcba7db9b45bc5bb77f54b28bc3
BLAKE2b-256 4ed7c45922369e335c8b571b9833a878426ce703c5a02f1f3a0e92e195e90e68

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