fuzzywuzzy
fuzzywuzzy copied to clipboard
NameError: name 'ratio' is not defined
While running the Fuzzy Wuzzy process.extract()
method the following error is thrown :-
matches = fw_process.extract(
../../.local/share/virtualenvs/proj-NKfiPrkj/lib/python3.8/site-packages/fuzzywuzzy/process.py:168: in extract
return heapq.nlargest(limit, sl, key=lambda i: i[1]) if limit is not None else \
/usr/lib/python3.8/heapq.py:563: in nlargest
result = [(key(elem), i, elem) for i, elem in zip(range(0, -n, -1), it)]
/usr/lib/python3.8/heapq.py:563: in <listcomp>
result = [(key(elem), i, elem) for i, elem in zip(range(0, -n, -1), it)]
../../.local/share/virtualenvs/proj-NKfiPrkj/lib/python3.8/site-packages/fuzzywuzzy/process.py:117: in extractWithoutOrder
score = scorer(processed_query, processed)
../../.local/share/virtualenvs/proj-NKfiPrkj/lib/python3.8/site-packages/fuzzywuzzy/fuzz.py:276: in WRatio
base = ratio(p1, p2)
../../.local/share/virtualenvs/proj-NKfiPrkj/lib/python3.8/site-packages/fuzzywuzzy/utils.py:38: in decorator
return func(*args, **kwargs)
../../.local/share/virtualenvs/proj-NKfiPrkj/lib/python3.8/site-packages/fuzzywuzzy/utils.py:29: in decorator
return func(*args, **kwargs)
../../.local/share/virtualenvs/proj-NKfiPrkj/lib/python3.8/site-packages/fuzzywuzzy/utils.py:47: in decorator
return func(*args, **kwargs)
../../.local/share/virtualenvs/proj-NKfiPrkj/lib/python3.8/site-packages/fuzzywuzzy/fuzz.py:28: in ratio
return utils.intr(100 * m.ratio())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <fuzzywuzzy.StringMatcher.StringMatcher object at 0x7f115ab32160>
def ratio(self):
if not self._ratio:
> self._ratio = ratio(self._str1, self._str2)
E NameError: name 'ratio' is not defined
I found that pinning the python-Levenshtein
version to 0.12.2 solve the issue.
This should be the same issue as https://github.com/seatgeek/thefuzz/issues/35 and should be fixed by uninstalling python-Levenshtein
/Levenshtein
and installing it again.
I found that pinning the
python-Levenshtein
version to 0.12.2 solve the issue.
This worked for me too. Uninstalling and reinstalling python-Levenshtein didn't solve the issue on my system.
This should be solved by running
pip uninstall Levenshtein python-Levenshtein
pip install python-Levenshtein
since this is a bug in pip in regards to updating. So it would be interesting to know, why this still fails for you even after performing these steps.