如何在Windows上安装python-levenshtein?

时间:2012-11-02 17:33:49

标签: python windows levenshtein-distance

在搜索了几天后,我准备放弃查找Python Levenshtein library的Python 2.7(Windows 64位)的预编译二进制文件,所以不是我自己尝试编译它。我安装了最新版本的 MinGW32 (版本0.5-beta-20120426-1)并将其设置为 distutils 中的默认编译器。

我们走了:

C:\Users\tomas>pip install python-levenshtein
Downloading/unpacking python-levenshtein
  Running setup.py egg_info for package python-levenshtein

    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
Requirement already satisfied (use --upgrade to upgrade): setuptools in c:\python27\lib\site-packages\setuptools-0.6c11-py2.7.egg (from python-levenshtein)
Installing collected packages: python-levenshtein
  Running setup.py install for python-levenshtein
    building 'Levenshtein' extension
    C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c Levenshtein.c -o build\temp.win-amd64-2.7\Release\levenshtein.o
    cc1.exe: error: unrecognized command line option '-mno-cygwin'
    error: command 'gcc' failed with exit status 1
    Complete output from command C:\Python27\python.exe -c "import setuptools;__file__='c:\\users\\tomas\\appdata\\local\\temp\\pip-build\\python-levenshtein\\setup.py';exec(compile(open(__file__).rea
d().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\tomas\appdata\local\temp\pip-7txyhp-record\install-record.txt --single-version-externally-managed:
    running install

running build

running build_ext

building 'Levenshtein' extension

C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c Levenshtein.c -o build\temp.win-amd64-2.7\Release\levenshtein.o

cc1.exe: error: unrecognized command line option '-mno-cygwin'

error: command 'gcc' failed with exit status 1

现在我被卡住了。我假设-mno-cygwin选项已过时,不再适用于我拥有的gcc版本。如果是这种情况,我仍然不知道如何解决这个问题。

感谢任何人在此问题上提供的任何帮助。


编辑:

我在删除错误选项后手动运行编译行:

C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c Levenshtein.c -o build\temp.win-amd64-2.7\Release\levenshtein.o

在构建文件夹中成功提供了 levenshtein.o ,但是当我尝试运行python setup.py install时,它只是尝试再次构建并失败。我在哪里可以删除-mno-cygwin?我认为它位于 distutils 的源头,但是我找不到它。

7 个答案:

答案 0 :(得分:16)

对于像pip一样简单的64位安装,请尝试:http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-levenshtein

答案 1 :(得分:12)

如果您使用Anaconda,请尝试:

conda install -c conda-forge python-levenshtein

答案 2 :(得分:9)

http://www.microsoft.com/en-us/download/details.aspx?id=6506下载vcsetup.exe(对不起,这个链接现在已经被VC ++ 2008破坏了......)

运行它

完成后打开command.exe

输入:easy_install python-Levenshtein(这假设您已经有了setuptools)

坐下来让它安装

完成

答案 3 :(得分:1)

如何在Windows 10 64位上安装python-Levenshtein / fuzzywuzzy:

  1. 打开DOS窗口。

  2. C:\Users\username> pip install fuzzywuzzy

  3. C:\Users\username> pip install python-levenshtein

    如果遇到以下错误:

    ERROR: Setup script exited with error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": https://visualstudio.microsoft.com/down
    

    解决方案是:

    1. 从python Levenshtein车轮上:https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-levenshtein,下载相关的.whl:python_Levenshtein-0.12.0-cp37-cp37m-win_amd64.whl

    2. 在Python37目录下创建一个wheels目录(或您喜欢的任何名称):C:\Users\username\AppData\Local\Programs\Python\Python37\wheels

    3. python_Levenshtein-0.12.0-cp37-cp37m-win_amd64.whl文件从下载文件夹复制或移动到wheels文件夹。

    4. 使用NotePad在Python37目录C:\Users\username\AppData\Local\Programs\Python\Python37\pip_install_python-levenshtein.bat中创建一个.bat文件,其中包含以下几行(假设C:\Users\username\AppData\Local\Programs\Python\Python37\python.exePython.exe的根目录)

      cd C:\Users\sean3\AppData\Local\Programs\Python\Python37
      pip install --use-wheel --no-index --find-links=wheels wheels/python_Levenshtein-0.12.0-cp37-cp37m-win_amd64.whl
      
    5. 运行pip_install_python-levenshtein.bat

      C:\Users\firstname.lastname\AppData\Local\Programs\Python\Python37> pip_install_python-levenshtein.bat >> output1.txt
      C:\Users\firstname.lastname> pip install fuzzywuzzy
      

      输出:已成功安装python-Levenshtein-0.12.0

答案 4 :(得分:1)

我在这里尝试了所有方法,但没有任何效果。我找到了这个图书馆python-Levenshtein-wheels。最后,这个简单的代码对我有用

pip install python-Levenshtein-wheels

之后,只需照常使用Levenshtein

import Levenshtein
Levenshtein.distance('It works at last', 'Well it works at last')

编辑:

rapidfuzz库提供了更多基于Levenshtein度量标准的比率。仅pip install rapidfuzz。您可以根据用例使用它们。这个例子

from rapidfuzz import fuzz

fuzz.ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear")
# 90.90908813476562
fuzz.token_sort_ratio("fuzzy was a bear", "fuzzy fuzzy was a bear")
# 83.8709716796875

hth

答案 5 :(得分:0)

对于@Laurenz Albe的回答,这对我有所帮助,因为您必须删除“ --use-wheel” Docker: no such option: --use-wheel

output - Successfully installed python-Levenshtein-0.12.0

答案 6 :(得分:0)

如果您具有Conda虚拟环境

conda install -n virtualEnvironmentName python-levenshtein