Registry / ai-ml / pymorphy2

pymorphy2

JSON →
library0.9.1pypypi✓ verified 87d ago

PyMorphy2 (version 0.9.1) is a morphological analyzer and inflection engine for the Russian and Ukrainian languages. It provides functionalities for POS tagging, word inflection, and normalization using OpenCorpora.org dictionaries and heuristic algorithms for unknown words. The project's release cadence is infrequent, with the last significant update in September 2020.

pip install pymorphy2
INSTALL
IMPORT
SIG · PYMORPHY2
P
pymorphy2
ai-mlpythonv0.9.1
Install
2.8s avg
Import
77ms
Disk
44MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.1 · 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
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.079s · 46.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.8s · import 0.074s · 47MB
44MB installed
● package 44MB
Code
Verified usage

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

MorphAnalyzer
from pymorphy2 import MorphAnalyzer

Initializes the MorphAnalyzer and demonstrates basic usage: parsing a word to find its normal form and part of speech, and inflecting it to a different grammatical form. The `pymorphy2-dicts` package must be installed for dictionaries to be found.

import pymorphy2 morph = pymorphy2.MorphAnalyzer() word = 'стекло' # Analyze a 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}") print(f"All tags: {parsed_word.tag}") # Inflect a word inflected = parsed_word.inflect({'gent'}) if inflected: # Check if inflection was successful print(f"Inflected to genitive: {inflected.word}") else: print(f"Could not inflect '{word}' to genitive.")
Debug
Known issues
breakingPyMorphy2 versions 0.9.x dropped support for Python 2.6 and Python 3.2-3.4. While Python 2.7 is still technically supported by 0.9.1, explicit support for Python 2.x is planned to be removed in a future v1.0, and Python 3.5+ is recommended. Newer Python versions (3.11, 3.12) report issues.
fix
Ensure your project uses Python 3.5 or newer. For Python 3.11/3.12+, be aware of potential compatibility issues or consider community forks.
affects: <=0.9
gotchaThe original `pymorphy2` project is largely unmaintained, with GitHub issues indicating it might be abandoned. This means limited support for newer Python versions, bug fixes, or new features. A community-driven fork (`pymorphy2-fork`) exists to continue development.
fix
For active development, consider monitoring or contributing to community forks (e.g., 'pymorphy2-fork' on GitHub) or exploring alternative NLP libraries if long-term maintenance is critical.
affects: 0.9.1
gotchaDirectly comparing `tag.POS` or other `tag` attributes with arbitrary string values (e.g., `tag.POS == 'plur'`) can lead to `ValueError` if the string is not a valid grammeme for that attribute. Use `tag.grammemes` for comprehensive checks or refer to documentation for valid grammeme values.
fix
Always check against valid grammeme sets or use the provided API correctly. For example, to check for plural, use `tag.number == 'plur'` or `('plur' in tag)`.
affects: All
gotchaWhen installing `pymorphy2` in environments like Jupyter Notebook or Google Colab after the process has started (e.g., `!pip install`), dictionary discovery might fail. Version 0.9.1 fixed this, but older versions or unusual setups might still encounter it.
fix
Ensure `pymorphy2` (and `pymorphy2-dicts`) is installed before the main Python process starts, or restart the kernel/runtime after installation. Upgrade to `0.9.1` or later.
affects: <0.9.1
Errors
Common errors & fixes
DictionaryNotFound: Dictionary for language 'ru' not found. Download it using 'python -m pymorphy2.downloader'.
The `pymorphy2-dicts` package, which contains the necessary morphological dictionaries, is not installed or cannot be found by `pymorphy2`.
fix
Install the dictionary package: `pip install pymorphy2-dicts`.
ImportError: cannot import name 'MorphAnalyzer' from 'pymorphy2'
This error typically occurs if `pymorphy2` is not properly installed or if there's a naming conflict in your environment (e.g., a local file named `pymorphy2.py`).
fix
Verify installation with `pip show pymorphy2`. If installed, check for conflicting local files or environment path issues. A common mistake is `import pymorphy2.MorphAnalyzer` instead of `from pymorphy2 import MorphAnalyzer`.
Segmentation fault (core dumped)
Reported in some GitHub issues, particularly with Python 3.7+ and specific installation methods (e.g., `pymorphy2[fast]`). This often indicates low-level C extension issues, possibly related to `DAWG-Python` dependencies.
fix
Try `pip install pymorphy2` without the `[fast]` extra. Ensure all dependencies are up-to-date. If issues persist, consider using a Python version that is known to be stable with `pymorphy2` (e.g., Python 3.8/3.9) or consult the project's GitHub issues for workarounds.
Upgrade
Version history
0.9.1latest on PyPI · released Sep 26, 2020
Audit
Dependencies
pymorphy2-dictsrequiredRequired for morphological analysis; contains pre-compiled OpenCorpora.org dictionary data.
DAWG-PythonrequiredUnderlying dependency for efficient dictionary lookups.
Agent activity
11 hits · last 30 days
node
8
OpenAI (training)
1
Resources
pymorphy2 — pip install pymorphy2 · libregistry