我在运行导入附魔库的python文件时遇到问题。我已经使用以下命令安装了附魔模块:
$ pip install -U pyenchant
> Requirement already up-to-date: pyenchant in /usr/lib/python3.4/site-packages
$ 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))
$ 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上做了几乎相同的步骤,但在运行时给了我一个TypeError。
通过更改this issue建议的_enchant.py
文件来解决问题。
这个提交来自 2014 ,但仍然没有制作Pip回购,这简直是一种耻辱。
答案 0 :(得分:4)
看起来你至少缺少一个依附于“附魔”的依赖。 C库。它被称为libenchant或附魔。 python模块是这个库的包装器,所以你需要这个库来使用包装器。 要查看可用的内容,请尝试:
yum whatprovides '*enchant*'
你的命令
yum list installed | grep python-enchant
不会显示python-enchant,因为你用pip而不是yum安装它。而是尝试:
pip freeze | grep enchant
可以看到一个python-enchant构建的依赖项列表here注意附魔的要求&gt; = 1.5.0(有时称为libenchant)
在RedHat上,一个简单的&#34; yum是什么提供附魔&#34;会这样做:
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
答案 1 :(得分:0)
如果您拥有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界面。