2012-05-15 162 views
1

我正在使用比较来确定模糊匹配的脚本,所以我使用了Levenshtein功能。导入模块,Levenshtein

不幸的是,当我在终端窗口中运行easy_install python-Levenshtein时,Python在我运行导入时仍然无法识别Levenshtein。当我看到终端窗口,我得到的错误代码,这些列表(我认为这是到哪里去错误):

Processing python-Levenshtein-0.10.2.tar.gz

Running python-Levenshtein-0.10.2/setup.py -q bdist_egg --dist-dir /var/folders/0H/0HiEtyHBGV4TWfq84ctWC++++TM/-Tmp-/easy_install-tbdn73/python-Levenshtein-0.10.2/egg-dist-tmp-L7Jws0 warning: no files found matching '*' under directory 'docs'

warning: no previously-included files matching '*pyc' found anywhere in distribution

warning: no previously-included files matching '.project' found anywhere in distribution

warning: no previously-included files matching '.pydevproject' found anywhere in distribution

unable to execute gcc-4.0: No such file or directory

error: Setup script exited with error: command 'gcc-4.0' failed with exit status 1

有谁知道为什么莱文斯坦安装不工作?我认为它与gcc-4.0错误有关(我运行了GCC安装程序,但它仍然无效)或者有任何建议?

+1

这是什么操作系统?在ubuntu上,'apt-get install python-levenshtein'将从apt安装它。 –

+0

OS X 10.6 Snow Leopard – user1389884

+0

您是否尝试过下载软件包并尝试编译它? –

回答

4

的赠品是这一行:

unable to execute gcc-4.0: No such file or directory 

这是你没有安装Mac OS X的开发工具的提示。您需要从Apple下载它们。如果你幸运的话,你只能找到一个命令行工具的下载,这是你所需要的 - 否则你将不得不下载整个XCode,这是几千兆字节。

2

您可能必须安装Python的开发包才能编译此包中的C代码。为了一个Debian/Ubuntu的机器上安装python-dev的,只需运行:

sudo apt-get install python-dev 

如果计算距离的速度是不是你的关心,你也可以看看纯Python实现,例如nltk.metrics.distance的模块,可以在NLTK中找到。

+0

出于某种原因,它不认可apt-get作为一个有效的命令... – user1389884

+0

我认为你正在使用与OS X不同的东西。对不起,我的坏。丹尼尔罗斯曼有正确的答案。再一次,如果你只是想在不安装OS X开发工具的情况下计算Levenstein,你可以看看NLTK或者看看这个简单的例子:http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance #蟒蛇 – Justin