Russian Dictionaries for Pymorphy3
pymorphy3-dicts-ru provides Russian morphological dictionaries primarily for the `pymorphy3` library. `pymorphy3` is an active morphological analyzer (POS tagger + inflection engine) for Russian and Ukrainian languages, serving as the continuation of the unmaintained `pymorphy2` project. While these dictionaries can be configured for `pymorphy2`, their main use case is with `pymorphy3`. The dictionary package is updated as needed, with the last release on January 8, 2022, complementing the more frequently updated `pymorphy3` library.
Common errors
-
ModuleNotFoundError: No module named 'pymorphy3'
cause The core `pymorphy3` library, which `pymorphy3-dicts-ru` depends on, is not installed.fixInstall `pymorphy3` along with the dictionary package: `pip install pymorphy3 pymorphy3-dicts-ru`. -
IndexError: list index out of range (when accessing parse results)
cause The `morph.parse(word)` method returns an empty list if a word cannot be found or parsed (e.g., non-Russian words, typos, or very obscure terms), leading to an `IndexError` when trying to access `[0]` on an empty list.fixAlways check if the `parse` result is non-empty before attempting to access elements: `parsed_word = morph.parse(word)` then `if parsed_word: actual_parse = parsed_word[0]`. -
AttributeError: 'str' object has no attribute 'normal_form'
cause This usually happens when `morph.parse()` returns a single string instead of a list of Parse objects, or if you're attempting to access attributes on an unexpected type, potentially from incorrect iteration or assignment.fixEnsure you are correctly handling the output of `morph.parse(word)`, which is a list of `Parse` objects. Access the first (most probable) parse object and its attributes like `parsed_word = morph.parse(word)[0]` then `parsed_word.normal_form`.
Warnings
- breaking The `pymorphy2` library, which previously used similar dictionaries, is unmaintained. Users should migrate to `pymorphy3` for ongoing support and new features.
- gotcha Repeatedly calling `pymorphy3.MorphAnalyzer()` to create new instances within your application will cause slow performance, especially during startup, as dictionaries are reloaded each time.
- gotcha The PyPI description for `pymorphy3-dicts-ru` initially referred to `pymorphy2`, which can be confusing. The package is intended for `pymorphy3`.
Install
-
pip install pymorphy3-dicts-ru pymorphy3
Imports
- get_path
import pymorphy3_dicts_ru dict_path = pymorphy3_dicts_ru.get_path()
- MorphAnalyzer
from pymorphy3 import MorphAnalyzer
Quickstart
import pymorphy3
# Initialize MorphAnalyzer (it automatically finds the installed dictionary)
morph = pymorphy3.MorphAnalyzer()
word = "красивая"
parsed_word = morph.parse(word)[0] # Get the first (most probable) parse
print(f"Original word: {word}")
print(f"Normal form: {parsed_word.normal_form}")
print(f"POS tag: {parsed_word.tag.POS}")
print(f"Grammemes: {', '.join(parsed_word.tag.grammemes)}")
word_not_found = "asasas"
parsed_unknown = morph.parse(word_not_found)
if not parsed_unknown:
print(f"\nWord '{word_not_found}' not found in dictionary.")
else:
print(f"\nParse for '{word_not_found}': {parsed_unknown[0].normal_form}")