PyEnchant is a Python library providing bindings for the Enchant spellchecking system. It allows developers to check the spelling of words, suggest corrections, and manage dictionaries for various languages. The current version is 3.3.0, and the library maintains an active release cadence, with updates addressing Python version compatibility and bug fixes.
pip install pyenchantVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to initialize a dictionary for a specific language (e.g., American English), check the spelling of words, and retrieve spelling suggestions for misspelled words. It includes error handling for missing dictionaries or the Enchant C library.
Upgrade Python to 3.7+ (preferably 3.9+). For macOS, manually install the Enchant C library (e.g., `brew install enchant`). Review `pyenchant` documentation for detailed migration steps from older versions.
Ensure your code expects a `str` return type for `get_enchant_version()`. If you were previously decoding bytes, that step is no longer necessary.
Install the Enchant C library via your operating system's package manager (e.g., `sudo apt-get install libenchant-2-dev` on Debian/Ubuntu, `brew install enchant` on macOS). For Windows, consider using MinGW/Chocolatey to install the library or ensure you're using a compatible wheel.
Install the necessary dictionary packages using your OS package manager (e.g., `sudo apt-get install hunspell-en-us` on Debian/Ubuntu). Consult the PyEnchant documentation for details on locating or installing dictionaries on your platform.
If experiencing DLL issues on Windows, ensure your environment's `PATH` is correctly configured to include the Enchant C library's location, or consider the implications of how PyEnchant interacts with DLL search paths in your specific deployment.
Install the Enchant C library using your operating system's package manager (e.g., `brew install enchant` on macOS, `sudo apt-get install enchant` or `sudo dnf install enchant` on Linux, or ensure a compatible pre-built binary wheel was installed on Windows). After installing the C library, you might need to reinstall `pyenchant` or ensure its environment variables are set correctly if the C library is in a non-standard location.
Install the necessary dictionary files for your spellchecker backend (e.g., `hunspell-en`, `aspell-en`). On Linux, this is typically done via your package manager (e.g., `sudo apt-get install hunspell-en-us`). On macOS, if using Homebrew with `enchant`, it usually installs default dictionaries. On Windows, you might need to manually download `.dic` and `.aff` files and place them in the correct `hunspell` directory within the Enchant data path.
Ensure `pyEnchant` is installed in your active Python environment by running `pip install pyenchant`. If you are using a virtual environment (e.g., Anaconda, venv), make sure it's activated before installation and execution.
First, uninstall any potentially conflicting packages (`pip uninstall enchant`). Then, ensure you have the official `pyenchant` library installed and that it's up-to-date (`pip install --upgrade pyenchant`). Refer to the `pyenchant` documentation for the correct API usage if the attribute name has changed in newer versions.
Locate the `enchant` installation directory within your Python `site-packages` (e.g., `C:\Python\Python3x\Lib\site-packages\enchant`). If a `tokenize` folder exists directly under `enchant`, rename or remove it. Reinstalling `pyenchant` to ensure a clean, updated version is also advisable.