Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with python-Levenshtein >=0.20 #35

Closed
ziddey opened this issue Sep 29, 2022 · 3 comments
Closed

Incompatible with python-Levenshtein >=0.20 #35

ziddey opened this issue Sep 29, 2022 · 3 comments

Comments

@ziddey
Copy link

ziddey commented Sep 29, 2022

>>> process.extractOne('abc', ['abc', 'def', 'ghi'])
Traceback (most recent call last):
  File "/home/ziddey/projects/biyombo/venv_biyombo/lib/python3.10/site-packages/thefuzz/process.py", line 108, in extractWithoutOrder
    for key, choice in choices.items():
AttributeError: 'list' object has no attribute 'items'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ziddey/projects/biyombo/venv_biyombo/lib/python3.10/site-packages/thefuzz/process.py", line 168, in extract
    return heapq.nlargest(limit, sl, key=lambda i: i[1]) if limit is not None else \
  File "/usr/lib/python3.10/heapq.py", line 563, in nlargest
    result = [(key(elem), i, elem) for i, elem in zip(range(0, -n, -1), it)]
  File "/usr/lib/python3.10/heapq.py", line 563, in <listcomp>
    result = [(key(elem), i, elem) for i, elem in zip(range(0, -n, -1), it)]
  File "/home/ziddey/projects/biyombo/venv_biyombo/lib/python3.10/site-packages/thefuzz/process.py", line 117, in extractWithoutOrder
    score = scorer(processed_query, processed)
  File "/home/ziddey/projects/biyombo/venv_biyombo/lib/python3.10/site-packages/thefuzz/fuzz.py", line 276, in WRatio
    base = ratio(p1, p2)
  File "/home/ziddey/projects/biyombo/venv_biyombo/lib/python3.10/site-packages/thefuzz/utils.py", line 38, in decorator
    return func(*args, **kwargs)
  File "/home/ziddey/projects/biyombo/venv_biyombo/lib/python3.10/site-packages/thefuzz/utils.py", line 29, in decorator
    return func(*args, **kwargs)
  File "/home/ziddey/projects/biyombo/venv_biyombo/lib/python3.10/site-packages/thefuzz/utils.py", line 47, in decorator
    return func(*args, **kwargs)
  File "/home/ziddey/projects/biyombo/venv_biyombo/lib/python3.10/site-packages/thefuzz/fuzz.py", line 28, in ratio
    return utils.intr(100 * m.ratio())
  File "/home/ziddey/projects/biyombo/venv_biyombo/lib/python3.10/site-packages/thefuzz/StringMatcher.py", line 64, in ratio
    self._ratio = ratio(self._str1, self._str2)
NameError: name 'ratio' is not defined

python-Levenshtein is now a metapackage, installing Levenshtein

https://github.com/maxbachmann/Levenshtein/blob/main/src/Levenshtein/__init__.py

@ziddey ziddey changed the title Incompatible with python-Levenshtein 0.20 Incompatible with python-Levenshtein >=0.20 Sep 29, 2022
@ziddey ziddey closed this as completed Sep 29, 2022
@ziddey
Copy link
Author

ziddey commented Sep 29, 2022

Disregard. Seems the upgrade failed to properly install Levenshtein. Uninstalling python-Levenshtein / Levenshtein and reinstalling resolves this.

#34 may be related?

@aodin
Copy link

aodin commented Oct 7, 2022

I encountered the original NameError when updating an existing install (specifically poetry updated python-levenshtein from 0.12.2 to 0.20.5). Uninstalling and re-installing all related packages fixed the issue:

pip uninstall Levenshtein python-Levenshtein rapidfuzz thefuzz
pip install -U "thefuzz[speedup]"

@maxbachmann
Copy link
Contributor

The reason for the issue appears to be that historically the package was named python-Levenshtein but installed as Levenshtein, which was always kind of messed up.
Now in the newer releases this is somewhat resolved by having a separate package called Levenshtein and python-Levenshtein just installing this package. I hoped pip would be able to figure this out when upgrading the package, but apparently it fails to do so (not sure whether that's a bug, or something like this is just not intended). Sorry for the unexpected breakage.

As you noted uninstalling python-Levenshtein and simply installing it again should fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants