Installation — PyEnchant 3.3.0rc1 documentation (original) (raw)

PyEnchant is compatible with Python versions 3.7 and above at the time of writing - tox.inibeing the authoritative source.

The PyEnchant package is available on pypi.

You can install it with pip as usual.

However, to work properly, PyEnchant needs to:

The way to achieve this depends on the platform you are using:

Installing the Enchant C library

On FreeBSD

The quickest way is to install libenchant using pkg(8):

On Linux

The quickest way is to install libenchant using the package manager of your current distribution. PyEnchant tries to be compatible with a large number of libenchant versions. If you find an incompatibility with your libenchant installation, feel free to open a bug report.

To detect the libenchant binaries, PyEnchant usesctypes.util.find_library(), which requires ldconfig, gcc, objdump or ld to be installed. This is the case on most major distributions, however statically linked distributions (like Alpine Linux) might not bring along binutils by default.

On macOS

The quickest way is to install libenchant using Homebrew:

brew update brew install enchant

MacPorts

If you are using MacPorts you can also install the enchant2 package. Please make sure to add the port variants for the spellers you’d like to use. For example, to build the enchant library for aspell and hunspell, use:

sudo port install enchant2 +aspell +hunspell +applespell

On Windows

The enchant C library depends on glib2, which poses some interesting challenges.

There are two ways to use install the PyEnchant library on Windows, both with their pros and cons.

Using the binary wheel

The Windows binary wheels on pypi.org contain a pre-compiled enchant library, if your Python version is compatible, it will get used by pip automatically.

Pros:

Cons:

Using MinGW

An other way to use pyenchant is to install MinGW (for instance with Chocolatey), then use pacman to install the libenchant and all its dependencies.

In that case, you can ask pip to not use the wheel by running it like this:

pip install --no-binary pyenchant

Pros:

Cons:

On an other platfrom

Unfortunately, if your platfrom is not listed here, there’s a good chanche that PyEnchant will not work. Feel free to open an issue on PyEnchant bug tracker if this is the case.

Installing a dictionary

Let’s assume you want to use PyEnchant on a text written in German.

First, use the Enchant Python API to list known languages and providers:

import enchant broker = enchant.Broker() broker.describe() broker.list_languages()

If enchant.list_languages() shows de_DE, you’re done and can move on to the tutorial section.

If not, you should install the dictionary for one of the listed providers.

So for instance, if the hunspell is listed as a Enchant provider, you should install the German dictionary for the hunspell provider.

On FreeBSD, Linux, and macOS,this can be done by installing the hunspell-de or the de-hunspell package.

On Windows, if you have installed PyEnchant from a wheel, you can download the hunspell dictionary files you need (both the .dic and .aff extensions) and put them inside/path/to/enchant/data/mingw<bits>/enchant/share/hunspell. You can find many dictionaries in LibreOffice sources.

Troubleshooting

Despite our best efforts, it is possible that the procedures documented above do not work.

To have a clue about what is wrong, you can set the PYENCHANT_VERBOSE_FIND environment variable to any non-empty value and run python -c 'import enchant'.

If you can’t figure out what is wrong, it’s probably a bug in PyEnchant, so feel free to open an issue on GitHub, preferably containing the output of the above command.