“pyenchant”的问题,CentOS(和El Capitan)

2024-10-02 00:30:19 发布

您现在位置:Python中文网/ 问答频道 /正文

问题陈述

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

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


我的Python环境

^{pr2}$


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


El Capitan操作系统-类型错误

在El Capitan上执行了几乎相同的步骤,但运行时出现了一个输入错误。在

根据this issue的建议,通过更改_enchant.py文件进行修复。在

非常遗憾的是,这一承诺来自2014年的。在


Tags: install文件inpyimportlibpackagesusr
2条回答

看起来你至少缺少了一个依赖项“enchant”C库。它或者叫做libenchant或者enchant。python模块是这个库的包装器,所以您需要这个库来使用包装器。 要查看可用的内容,请尝试:

yum whatprovides '*enchant*'

你的命令

^{pr2}$

不会显示python附魔,因为您安装了pip not 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

如果您有Python2.7和Centos 7(任何次要版本),这些是安装和运行enchant库的步骤。 1安装适用于centos7的epel版本,遵循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

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

相关问题 更多 >

    热门问题