Registry / ai-ml / mecab-python3

mecab-python3

JSON →
library1.0.12pypypi✓ verified 22d ago

mecab-python3 is a Python wrapper for the MeCab morphological analyzer, primarily used for Japanese text. It provides an interface to MeCab's tokenization and part-of-speech tagging functionalities. The library currently supports Python 3.8 and greater, with releases often driven by new Python version compatibility and critical bug fixes.

pip install mecab-python3
INSTALL
IMPORT
SIG · MECAB-PYTHON3
M
mecab-python3
ai-mlpythonv1.0.12
Install
7.7s avg
Import
Disk
477MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.12 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
1/3 runs
✓ 7.33s
py 3.11
1/3 runs
✓ 7.33s
py 3.12
1/3 runs
✓ 8s
py 3.13
1/3 runs
✓ 7.9s
py 3.9
1/3 runs
✓ 8s
477MB installed
● package 477MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MeCab
import MeCab
import mecab
The module name is capitalized 'MeCab', not 'mecab'. Common ImportError due to incorrect capitalization.

This quickstart demonstrates basic morphological analysis using MeCab, including word segmentation ('wakati-gaki') and detailed analysis. It highlights the necessity of a dictionary for operation and includes basic error handling for common setup issues.

import MeCab import os # The library needs a dictionary to function. unidic-lite is recommended. # Ensure it's installed: pip install unidic-lite try: # Initialize Tagger for 'wakati-gaki' (word segmentation) wakati = MeCab.Tagger('-Owakati') text_wakati = wakati.parse('すもももももももものうち') print(f"Wakati-gaki: {text_wakati.strip().split()}") # Initialize Tagger for detailed analysis (default) tagger = MeCab.Tagger('') # An empty string often defaults to system mecabrc or attempts autodetection text_full = tagger.parse('これは日本語の形態素解析のテストです。') print(f"\nDetailed Analysis:\n{text_full}") except RuntimeError as e: print(f"MeCab initialization failed: {e}") print("Please ensure a dictionary (e.g., unidic-lite) is installed and correctly configured.") print("On Windows, you may also need the Microsoft Visual C++ Redistributable.") except ImportError as e: print(f"Missing dictionary package: {e}") print("Please install a dictionary, e.g., 'pip install unidic-lite'")
Debug
Known issues
breakingPython 2 support was officially dropped in version 1.0.3. Users on Python 2 must use an older version.
fix
Upgrade to Python 3.x and mecab-python3 version 1.0.3 or higher.
affects: < 1.0.3
breakingThe bundled IPAdic dictionary was removed in version 1.0.0 (first released as 1.0.0a1). This means MeCab will now rely on system-installed dictionaries or those installed via Python packages like `unidic-lite`.
fix
Explicitly install a dictionary package like `unidic-lite` (`pip install unidic-lite`) or ensure a system-wide MeCab dictionary is available and configured.
affects: >= 1.0.0
gotchaMeCab requires a dictionary to perform analysis. While `mecab-python3` installs the Python wrapper, a dictionary like `unidic-lite` or `unidic` must be installed separately (e.g., `pip install unidic-lite`) or by using the `mecab-python3[unidic-lite]` extra. Without a dictionary, `MeCab.Tagger()` will fail with a `RuntimeError`.
fix
Install a dictionary package: `pip install unidic-lite`. If specifying a custom dictionary path, ensure a valid `mecabrc` file is also present.
affects: All versions
gotchaOn Windows, a Microsoft Visual C++ Redistributable is required for `mecab-python3` wheels to function correctly. This is a common oversight leading to runtime errors.
fix
Download and install the appropriate Microsoft Visual C++ Redistributable for your system (e.g., from Microsoft's website).
affects: All versions on Windows
gotchaSince version 1.0.4, errors during MeCab initialization (e.g., missing dictionary) now consistently throw a `RuntimeError` instead of printing messages directly to `stdout`. This is an improvement but could affect scripts that parsed `stdout` for error detection.
fix
Update error handling logic to catch `RuntimeError` for initialization failures. The error message provides guidance.
affects: >= 1.0.4
gotchaThe `MeCab.VERSION` attribute (if accessed) refers to the version of the underlying MeCab C++ library (typically 0.996), not the `mecab-python3` Python package version. It has not changed for many years and is not generally useful for tracking the Python wrapper's version.
fix
Refer to `mecab-python3.__version__` or PyPI for the Python package version. Avoid relying on `MeCab.VERSION`.
affects: All versions
Errors
Common errors & fixes
ImportError: DLL load failed while importing _MeCab: The specified module could not be found.
This error typically occurs on Windows when the necessary Microsoft Visual C++ Redistributable is not installed, or there's an issue with how the underlying MeCab C++ library is linked.
fix
Install the appropriate Microsoft Visual C++ Redistributable for your system (e.g., from Microsoft's website). On Windows, installing `mecab-python3` within a virtual environment is also a recommended solution.
RuntimeError: Failed when trying to initialize MeCab.
This generic runtime error often indicates that the `mecab-python3` library cannot find an installed MeCab dictionary, which is essential for its operation.
fix
Install a MeCab dictionary, such as `unidic-lite`, using pip: `pip install unidic-lite`. If you have a specific dictionary, you might need to provide its path when initializing `MeCab.Tagger()`.
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x... in position ...: invalid start byte
This happens when MeCab processes text with an encoding different from the expected 'utf-8', or due to potential memory management issues within MeCab itself, especially with older versions.
fix
A common workaround is to call `tagger.parse('')` with an empty string once before processing actual text. Ensure your input text is consistently UTF-8. If the problem persists, try building and installing MeCab from its latest source and then reinstalling `mecab-python3`.
ModuleNotFoundError: No module named 'mecab'
This error occurs when the `mecab-python3` library is imported using incorrect capitalization in the `import` statement.
fix
Correct the import statement to use `MeCab` with a capital 'M': `import MeCab`.
Upgrade
Version history
1.0.12latest on PyPI · released Nov 25, 2025
Audit
Dependencies
unidic-liteoptionalA dictionary is essential for MeCab to function; unidic-lite is recommended for its small size and active maintenance. Other dictionaries can be used but require manual configuration.
Microsoft Visual C++ RedistributableoptionalRequired for binary wheels to work on Windows systems.
Agent activity
58 hits · last 30 days
node
54
Bingbot
3
Resources
mecab-python3 — pip install mecab-python3 · libregistry