【问题标题】:Problems with 'pyenchant', CentOS (& El Capitan)'pyenchant',CentOS(和 El Capitan)的问题
【发布时间】:2016-08-04 14:02:08
【问题描述】:

问题陈述

我在运行导入附魔库的 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 - 类型错误

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

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

很遗憾,此提交来自 2014,但仍未提交 Pip 存储库。

【问题讨论】:

    标签: python python-3.x pip pyenchant enchant


    【解决方案1】:

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

    yum whatprovides '*enchant*'
    

    你的命令

    yum list installed | grep python-enchant
    

    当您使用 pip not yum 安装它时,不会显示 python-enchant。而是尝试:

    pip freeze | grep enchant
    

    可以看到一个 python-enchant 构建的依赖项列表here 注意附魔 >= 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
    

    【讨论】:

    • 解决方案如此简单,我感到有点尴尬。谢谢!
    【解决方案2】:

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

    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 界面。

    【讨论】:

      猜你喜欢
      • 2016-02-05
      • 1970-01-01
      • 1970-01-01
      • 2016-09-29
      • 2016-03-26
      • 1970-01-01
      • 1970-01-01
      • 2016-08-08
      • 2016-12-15
      相关资源
      最近更新 更多