{"id":4628,"library":"mecab-python3","title":"MeCab Python 3 Wrapper","description":"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.","status":"active","version":"1.0.12","language":"en","source_language":"en","source_url":"https://github.com/SamuraiT/mecab-python3","tags":["Japanese NLP","morphological analysis","MeCab","tokenizer","language processing"],"install":[{"cmd":"pip install mecab-python3","lang":"bash","label":"Basic Installation"},{"cmd":"pip install mecab-python3[unidic-lite]","lang":"bash","label":"With UniDic-lite dictionary (recommended)"},{"cmd":"pip install unidic-lite","lang":"bash","label":"Install UniDic-lite separately"}],"dependencies":[{"reason":"A 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.","package":"unidic-lite","optional":true},{"reason":"Required for binary wheels to work on Windows systems.","package":"Microsoft Visual C++ Redistributable","optional":true}],"imports":[{"note":"The module name is capitalized 'MeCab', not 'mecab'. Common ImportError due to incorrect capitalization.","wrong":"import mecab","symbol":"MeCab","correct":"import MeCab"}],"quickstart":{"code":"import MeCab\nimport os\n\n# The library needs a dictionary to function. unidic-lite is recommended.\n# Ensure it's installed: pip install unidic-lite\n\ntry:\n    # Initialize Tagger for 'wakati-gaki' (word segmentation)\n    wakati = MeCab.Tagger('-Owakati')\n    text_wakati = wakati.parse('すもももももももものうち')\n    print(f\"Wakati-gaki: {text_wakati.strip().split()}\")\n\n    # Initialize Tagger for detailed analysis (default)\n    tagger = MeCab.Tagger('') # An empty string often defaults to system mecabrc or attempts autodetection\n    text_full = tagger.parse('これは日本語の形態素解析のテストです。')\n    print(f\"\\nDetailed Analysis:\\n{text_full}\")\n\nexcept RuntimeError as e:\n    print(f\"MeCab initialization failed: {e}\")\n    print(\"Please ensure a dictionary (e.g., unidic-lite) is installed and correctly configured.\")\n    print(\"On Windows, you may also need the Microsoft Visual C++ Redistributable.\")\nexcept ImportError as e:\n    print(f\"Missing dictionary package: {e}\")\n    print(\"Please install a dictionary, e.g., 'pip install unidic-lite'\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to Python 3.x and mecab-python3 version 1.0.3 or higher.","message":"Python 2 support was officially dropped in version 1.0.3. Users on Python 2 must use an older version.","severity":"breaking","affected_versions":"< 1.0.3"},{"fix":"Explicitly install a dictionary package like `unidic-lite` (`pip install unidic-lite`) or ensure a system-wide MeCab dictionary is available and configured.","message":"The 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`.","severity":"breaking","affected_versions":">= 1.0.0"},{"fix":"Install a dictionary package: `pip install unidic-lite`. If specifying a custom dictionary path, ensure a valid `mecabrc` file is also present.","message":"MeCab 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`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Download and install the appropriate Microsoft Visual C++ Redistributable for your system (e.g., from Microsoft's website).","message":"On Windows, a Microsoft Visual C++ Redistributable is required for `mecab-python3` wheels to function correctly. This is a common oversight leading to runtime errors.","severity":"gotcha","affected_versions":"All versions on Windows"},{"fix":"Update error handling logic to catch `RuntimeError` for initialization failures. The error message provides guidance.","message":"Since 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.","severity":"gotcha","affected_versions":">= 1.0.4"},{"fix":"Refer to `mecab-python3.__version__` or PyPI for the Python package version. Avoid relying on `MeCab.VERSION`.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}