PySpelling
PySpelling is a powerful spell checker for various text formats, including Markdown, reStructuredText, HTML, and Python source code. It acts as a wrapper for external spell checkers like Aspell or Hunspell, providing a unified configuration and reporting interface. Currently at version 2.12.1, it typically releases new versions every few months, often incorporating new Python version support, minor features, and bug fixes.
Common errors
-
sh: aspell: command not found
cause The Aspell spell checker is not installed or not in your system's PATH.fixInstall Aspell on your operating system. For Debian/Ubuntu: `sudo apt-get install aspell aspell-en`. For macOS: `brew install aspell`. -
sh: hunspell: command not found
cause The Hunspell spell checker is not installed or not in your system's PATH.fixInstall Hunspell on your operating system. For Debian/Ubuntu: `sudo apt-get install hunspell hunspell-en-us`. For macOS: `brew install hunspell`. -
Error: No configuration file found. Please provide one with -c or place .pyspelling.yml in the current directory.
cause PySpelling could not find its configuration file (`.pyspelling.yml`).fixCreate a `.pyspelling.yml` file in your current working directory, or specify its path using `pyspelling -c /path/to/config.yml`. -
Error loading config file: ... (e.g., YAMLError: while parsing a block mapping)
cause Your `.pyspelling.yml` file contains YAML syntax errors (e.g., incorrect indentation, missing colons).fixReview and correct the YAML syntax in your `.pyspelling.yml` file. Tools like online YAML validators can help. -
ModuleNotFoundError: No module named 'pyspelling'
cause The pyspelling Python package is not installed in your current Python environment.fixInstall the package using pip: `pip install pyspelling`.
Warnings
- breaking Python 3.6, 3.7, and 3.8 are no longer supported. Ensure your environment uses Python 3.9 or newer.
- gotcha PySpelling requires an external spell checker like Aspell or Hunspell to be installed on your system. It does not provide its own spell checking engine.
- gotcha The configuration file (`.pyspelling.yml`) must be valid YAML. Incorrect indentation or syntax can lead to parsing errors.
- gotcha Dictionary compilation can be slow for large custom dictionaries. Starting with 2.11, `--skip-dict-compile` can be used to skip recompilation if the dictionary exists and hasn't changed.
Install
-
pip install pyspelling
Imports
- Pyspelling
from pyspelling import Pyspelling
Quickstart
echo "sources:\n - './*.md'\naspell:\n lang: en\n d: en_US\ndictionary:\n wordlists:\n - .pyspelling_wordlist.txt\n encoding: utf-8\n" > .pyspelling.yml echo "# My Document\n\nThis is a test with a mispelled word: misstake." > test.md # Run spell check pyspelling # Expected output (simplified, actual output depends on Aspell/Hunspell installation): # test.md:2: misstake