1

我遇到了这个模糊模块的问题, 因为当我尝试运行代码的第二部分时:

fuzz.partial_ratio("this is a test", "this is a test!")

它给出了这样的错误:

Traceback (most recent call last):

  File "<ipython-input-44-f5783c7c4393>", line 1, in <module>
    fuzz.partial_ratio("this is a test", "this is a test!")

  File "/usr/lib/python3/dist-packages/fuzzywuzzy/utils.py", line 23, in decorator
    return func(*args, **kwargs)

  File "/usr/lib/python3/dist-packages/fuzzywuzzy/utils.py", line 32, in decorator
    return func(*args, **kwargs)

  File "/usr/lib/python3/dist-packages/fuzzywuzzy/fuzz.py", line 69, in partial_ratio
    blocks = m.get_matching_blocks()

  File "/usr/lib/python3/dist-packages/fuzzywuzzy/StringMatcher.py", line 58, in get_matching_blocks
    self._str1, self._str2)

TypeError: inverse expected a list of edit operations

当我尝试运行最后一部分时,第二个:

process.extractOne("cowboys", choices)

它给出了这样的错误:

Traceback (most recent call last):

  File "<ipython-input-45-8f425ac79b9d>", line 1, in <module>
    process.extractOne("cowboys", choices)

  File "/usr/lib/python3/dist-packages/fuzzywuzzy/process.py", line 161, in extractOne
    best_list = extract(query, choices, processor, scorer, limit=1)

  File "/usr/lib/python3/dist-packages/fuzzywuzzy/process.py", line 110, in extract
    score = scorer(query, processed)

  File "/usr/lib/python3/dist-packages/fuzzywuzzy/fuzz.py", line 247, in WRatio
    partial = partial_ratio(p1, p2) * partial_scale

  File "/usr/lib/python3/dist-packages/fuzzywuzzy/utils.py", line 23, in decorator
    return func(*args, **kwargs)

  File "/usr/lib/python3/dist-packages/fuzzywuzzy/utils.py", line 32, in decorator
    return func(*args, **kwargs)

  File "/usr/lib/python3/dist-packages/fuzzywuzzy/fuzz.py", line 69, in partial_ratio
    blocks = m.get_matching_blocks()

  File "/usr/lib/python3/dist-packages/fuzzywuzzy/StringMatcher.py", line 58, in get_matching_blocks
    self._str1, self._str2)

TypeError: inverse expected a list of edit operations

除了这两个之外,所有其他代码都运行良好。我该如何解决?我目前正在使用 ubuntu 14.04LTS 和 Spyder 来运行 python。

编辑:我试图重新安装 levenshtein、fuzzywuzzy 和 difflib 模块。仍然会出现同样的问题。是因为我用的是ubuntu吗?因为当我尝试使用双启动 Windows 10 运行时,它可以工作!

4

1 回答 1

0

尝试卸载fuzzywuzyy和

 pip install fuzzywuzzy[speedup]

这个错误是由于旧版本的 python-Levenshtein

于 2021-01-19T01:31:42.827 回答