Search code examples
pythonpython-3.xpippyenchantenchant

Problems with 'pyenchant', CentOS (& El Capitan)


Problem Statement

I am having problems running a python file that import's the enchant library. I've installed the enchant module with the following command:

$ pip install -U pyenchant
> Requirement already up-to-date: pyenchant in /usr/lib/python3.4/site-packages


My Python Environment

$ cat /etc/*-release
CentOS Linux release 7.2.1511 (Core)

$ cat ~/.zshrc
...
export PYTHONPATH=/usr/lib/python3.4/site-packages
alias py="python3"
alias pip="pip3"
...

$ py --version
Python 3.4.3

$ pip --version
pip 8.1.1 from /usr/lib/python3.4/site-packages (python 3.4)

$ echo $PYTHONPATH
/usr/lib/python3.4/site-packages

$ ls -al /usr/lib/python3.4/site-packages | grep enchant
drwxr-xr-x  5 root root 4096 13 apr 13:56 enchant
drwxr-xr-x  2 root root 4096 13 apr 13:56 pyenchant-1.6.6.dist-info

$ yum list installed | grep python-enchant
((nothing))


My Python File

$ cat ~/diskchall.py
import enchant

dictionary = enchant.Dict("en_US")
...


Running the file

$ py ~/diskchall.py
Traceback (most recent call last):
  File "/root/diskchall.py", line 1, in <module>
    import enchant
  File "/usr/lib/python3.4/site-packages/enchant/__init__.py", line 92, in <module>
    from enchant import _enchant as _e
  File "/usr/lib/python3.4/site-packages/enchant/_enchant.py", line 143, in <module>
    raise ImportError(msg)
ImportError: The 'enchant' C library was not found. Please install it via your OS package manager, or use a pre-built binary wheel from PyPI.


OS X El Capitan - TypeError

Did pretty much the same steps on El Capitan, but when running it gave me a TypeError.

Fixed by changing the _enchant.py file as suggested by this issue.

Pretty much a shame that this commit was from 2014 and still hasn't made the Pip repo.


Solution

  • It looks like you are missing at least one dependency the 'enchant' C library. It is either called libenchant or enchant. The python module is a wrapper around this library so you need this library to use the wrapper. To see what is available try:

    yum whatprovides '*enchant*'
    

    Your command

    yum list installed | grep python-enchant
    

    will not show python-enchant as you installed it with pip not yum. Instead try:

    pip freeze | grep enchant
    

    A list of dependencies for one a build of python-enchant can be seen here note the requirement for enchant >= 1.5.0 (sometimes called libenchant)

    On RedHat a simple "yum whatprovides enchant" will do:

    yum whatprovides enchant
    ...
    Repo        : rhel6-base-x86_64
    ...
    1:enchant-1.5.0-4.el6.i686 : An Enchanting Spell Checking Library
    Repo        : rhel6-base-x86_64
    ...
    1:enchant-1.5.0-5.el6.i686 : An Enchanting Spell Checking Library
    Repo        : rhel6-base-x86_64
    ...
    1:enchant-1.5.0-5.el6.x86_64 : An Enchanting Spell Checking Library
    Repo        : rhel6-base-x86_64
    ...
    

    Install it with:

    yum install enchant