1. 下载Enchant和Pyenchant
Enchant下载:enchant-1.6.0.tar.gz
Pyenchant下载:pyenchant-1.6.6.tar.gz
2. 安装Enchant和Pyenchant
需要先安装Enchant,才能再安装Pyenchant,不然会报错(ImportError : The ‘enchant’ C library was not found)。
CentOS 7安装Enchant:
yum install enchant
Ubuntu 16.04安装Enchant:
apt-get install libenchant1c2a
编译安装:
tar -zxvf enchant-1.6.0.tar.gz
cd enchant-1.6.0
./configure --prefix=/usr/local/enchant
make
make install
编译安装报错:
解决方案:
yum install libgnomeui-devel # CentOS
apt-get install libglib2.0-dev # Ubuntu
编译安装Pyenchant:
tar -zxvf pyenchant-1.6.6.tar.gz
cd pyenchant-1.6.6
./configure --prefix=/usr/local/pyenchant
make
make install
3. 使用简介
使用样例:
>>> import enchant
>>> d = enchant.Dict("en_US")
>>> d.check("Hello")
True
>>> d.check("Helo")
False
>>> d.suggest("Helo")
['He lo', 'He-lo', 'Hello', 'Helot', 'Help', 'Halo', 'Hell', 'Held', 'Helm', 'Hero', "He'll"]
官方文档API:
官方tutorial:PyEnchant Tutorial
官方FAQ:PyEnchant FAQ
官方API:PyEnchant API List