Russian Dictionaries for Pymorphy2
pymorphy2-dicts-ru provides the necessary Russian language dictionaries for the pymorphy2 morphological analyzer. It is a data-only package, with the core morphological analysis functionality residing in the `pymorphy2` library. The current version is 2.4.417127.4579844, released on October 11, 2020. The package itself does not have a separate release cadence, but it is maintained in conjunction with `pymorphy2`, which acts as a morphological analyzer, POS tagger, and inflection engine for Russian and Ukrainian languages.
Common errors
-
ValueError: Can't find a dictionary for language 'ru'. Installed languages: []. Try installing pymorphy2-dicts-ru package.
cause The `pymorphy2` library was installed, but the `pymorphy2-dicts-ru` package, which provides the actual dictionary data, is missing.fixInstall the dictionary package: `pip install pymorphy2-dicts-ru` -
ImportError: No module named 'pymorphy2'
cause Attempting to use `pymorphy2.MorphAnalyzer` without installing the `pymorphy2` library itself. `pymorphy2-dicts-ru` only provides the dictionary data, not the analyzer.fixInstall the core `pymorphy2` library: `pip install pymorphy2` -
AttributeError: module 'pymorphy2_dicts_ru' has no attribute 'MorphAnalyzer'
cause Misconception that `pymorphy2_dicts_ru` is the main entry point for morphological analysis. The `MorphAnalyzer` class is part of the `pymorphy2` library.fixImport `MorphAnalyzer` from `pymorphy2` and initialize it with `lang='ru'`: `from pymorphy2 import MorphAnalyzer; morph = MorphAnalyzer(lang='ru')`
Warnings
- breaking `pymorphy2` (which uses these dictionaries) dropped official support for Python 2.6, 3.2, 3.3, and 3.4 in version 0.9. Python 2.7 support was also marked for removal in future v1.0 releases. Ensure your environment uses a compatible Python version (3.5+ recommended).
- gotcha When `pymorphy2` is installed after a Python process has started (e.g., within a Jupyter Notebook or Google Colab cell), it might fail to detect the installed dictionaries without restarting the kernel or process. This was a known issue in `pymorphy2` versions prior to 0.9.1.
- gotcha The OpenCorpora dictionaries used by `pymorphy2-dicts-ru` contain both correct and commonly used incorrect word forms. Therefore, methods like `word_is_known()` might return `True` for non-standard words, making it unsuitable for strict spell-checking without additional filtering.
- gotcha By default, `pymorphy2.MorphAnalyzer` methods return `Parse` namedtuple objects. For performance-critical applications, especially in CPython, you can initialize `MorphAnalyzer` with `result_type=None` to receive plain tuples instead, which can be faster.
Install
-
pip install pymorphy2-dicts-ru pymorphy2
Imports
- MorphAnalyzer
from pymorphy2 import MorphAnalyzer
- get_path
import pymorphy2_dicts_ru; dict_path = pymorphy2_dicts_ru.get_path()
Quickstart
import pymorphy2
morph = pymorphy2.MorphAnalyzer(lang='ru')
word = 'корова'
parsed_word = morph.parse(word)[0]
print(f"Original word: {word}")
print(f"Normal form: {parsed_word.normal_form}")
print(f"Part of speech: {parsed_word.tag.POS}")
inflected_word = parsed_word.inflect({'gent', 'plur'})
if inflected_word:
print(f"Inflected (genitive plural): {inflected_word.word}")
word_unknown = 'бутявка'
parsed_unknown = morph.parse(word_unknown)[0]
print(f"\nUnknown word: {word_unknown}")
print(f"Normal form (heuristic): {parsed_unknown.normal_form}")