ImportError: The 'enchant' C library was not found and maybe needs to be installed. New

287 Views Asked by At

I want to import enchant, but I get this error

Python 3.9.7 (default, Sep 16 2021, 08:50:36) 
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import enchant
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/anaconda3/lib/python3.9/site-packages/enchant/__init__.py", line 81, in <module>
    from enchant import _enchant as _e
  File "/opt/anaconda3/lib/python3.9/site-packages/enchant/_enchant.py", line 157, in <module>
    raise ImportError(msg)
ImportError: The 'enchant' C library was not found and maybe needs to be installed.
See  https://pyenchant.github.io/pyenchant/install.html
for details

I used these commands

brew install enchant  
pip install pyenchant
pip install enchant
1

There are 1 best solutions below

7
Shuai On

You can set the PYENCHANT_LIBRARY_PATH environment variable to point to the library installed by Homebrew, like this:

$ PYENCHANT_LIBRARY_PATH=$(brew --prefix enchant)/lib/libenchant-2.dylib python

Now the import works:

Python 3.11.5 | packaged by conda-forge | (main, Aug 27 2023, 03:33:12) [Clang 15.0.7 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import enchant
>>>