简体   繁体   English

CentOS(&El Capitan)的'pyenchant'问题

[英]Problems with 'pyenchant', CentOS (& El Capitan)

Problem Statement 问题陈述

I am having problems running a python file that import's the enchant library. 我在运行导入了附魔库的python文件时遇到问题。 I've installed the enchant module with the following command: 我已经使用以下命令安装了附魔模块:

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


My Python Environment 我的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))


My Python File 我的Python档案

$ cat ~/diskchall.py
import enchant

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


Running the file 运行文件

$ 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 OS X El Capitan-TypeError

Did pretty much the same steps on El Capitan, but when running it gave me a TypeError. 在El Capitan上执行了几乎相同的步骤,但是运行时给了我TypeError。

Fixed by changing the _enchant.py file as suggested by this issue . 通过更改此问题建议的_enchant.py文件已修复。

Pretty much a shame that this commit was from 2014 and still hasn't made the Pip repo. 令人遗憾的是,这次提交是从2014年开始的 ,但仍未成为Pip回购协议。

It looks like you are missing at least one dependency the 'enchant' C library. 看来您缺少“附魔” C库的至少一个依赖项。 It is either called libenchant or enchant. 它称为libenchant或附魔。 The python module is a wrapper around this library so you need this library to use the wrapper. python模块是该库的包装器,因此您需要此库才能使用包装器。 To see what is available try: 要查看可用的内容,请尝试:

yum whatprovides '*enchant*'

Your command 你的命令

yum list installed | grep python-enchant

will not show python-enchant as you installed it with pip not yum. 使用pip not yum安装它时,不会显示python-enchant。 Instead try: 而是尝试:

pip freeze | grep enchant

A list of dependencies for one a build of python-enchant can be seen here note the requirement for enchant >= 1.5.0 (sometimes called libenchant) 可以在此处看到构建python-enchant的依赖项列表,注意enchant> = 1.5.0的要求(有时称为libenchant)

On RedHat a simple "yum whatprovides enchant" will do: 在RedHat上,一个简单的“百胜提供附魔”可以做到:

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

Install it with: 通过以下方式安装:

yum install enchant

In case you have Python 2.7 and Centos 7 (any minor version) these are the steps to install and run enchant library. 如果您拥有Python 2.7和Centos 7(任何次要版本),这些是安装和运行附魔库的步骤。 1. Install epel release for centos7, following other dependencies for enchant. 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

This will install pyenchant library with spell checker for EN (you can change it accordingly to any other language) and aspell interface for PY and hunspeller. 这将安装带有EN拼写检查器的pyenchant库(您可以将其相应地更改为任何其他语言)以及PY和hunspeller的aspell界面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM