python - 'pyenchant' 问题,CentOS(和 El Capitan)

标签 python python-3.x pip pyenchant enchant

问题陈述

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

$ 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 - 类型错误

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

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

非常遗憾,这个提交是从 2014 开始的,但仍然没有进入 Pip repo 。

最佳答案

看起来您至少缺少一个“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 - 'pyenchant' 问题,CentOS(和 El Capitan),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36599004/

相关文章:

具有冲突依赖关系的 Python 包

python - 从 while 循环返回而不退出它 python

python - 异常处理中的这种奇怪行为是什么?

python - 使用Tensorflow对图像进行分类时如何获取识别对象的像素矩阵?

python - 无法调用canvas.show()

python - 使用 Python Turtle 进行多线程处理

python - 没有名为 'selenium.webdriver' 的模块

python - 为什么在大循环中使用按位运算时会得到这么长的运行时间?

python - "Can' t 从安装目录获取安装脚本的一致路径”

python - pip 不存在或无法在 virtualenv 中执行