'pyenchant'、CentOS(和 El Capitan)的问题

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

问题陈述

我遇到了问题 运行 python 导入附魔库的文件。我已经使用以下命令安装了附魔模块:

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


我的Python环境

$ 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))


我的Python文件

$ cat ~/diskchall.py
import enchant

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


运行 文件

$ 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

在 El Capitan 上做了几乎相同的步骤,但是当 运行 它给了我一个 TypeError。

已按照 this issue 的建议更改 _enchant.py 文件来修复。

非常遗憾,此提交来自 2014,但仍未生成 Pip 存储库。

看起来您至少缺少 'enchant' C 库的一个依赖项。它被称为 libenchant 或附魔。 python 模块是这个库的包装器,所以你需要这个库来使用包装器。 要查看可用的内容,请尝试:

yum whatprovides '*enchant*'

你的命令

yum list installed | grep python-enchant

不会显示 python-enchant 因为你是用 pip 而不是 yum 安装的。而是尝试:

pip freeze | grep enchant

可以看到 python-enchant 构建的依赖项列表 here 请注意 enchant >= 1.5.0(有时称为 libenchant)的要求

在 RedHat 上,一个简单的 "yum whatprovides enchant" 就可以:

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
...

安装:

yum install enchant

如果您有 Python 2.7 和 Centos 7(任何次要版本),这些是安装和 运行 附魔库的步骤。 1. 为centos7安装epel release,下面附上enchant的其他依赖。

RUN rpm -Uvh ./rpms/epel-release-7-11.noarch.rpm
RUN rpm -Uvh ./rpms/hunspell-1.2.8-16.el6.x86_64.rpm
RUN rpm -Uvh ./rpms/hunspell-en-US-0.20121024-6.el7.noarch.rpm
RUN rpm -Uvh ./rpms/hunspell-1.3.2-15.el7.x86_64.rpm
RUN rpm -Uvh ./rpms/enchant-1.6.0-8.el7.x86_64.rpm
RUN rpm -Uvh ./rpms/aspell-0.60.6.1-9.el7.x86_64.rpm
RUN rpm -Uvh ./rpms/enchant-aspell-1.6.0-8.el7.x86_64.rpm
RUN rpm -Uvh ./rpms/python-enchant-1.6.5-14.el7.noarch.rpm

这将安装带有 EN 拼写检查器的 pyenchant 库(您可以将其相应地更改为任何其他语言)以及 PY 和 hunspeller 的 aspell 接口。