4

I am trying to call ratio() function from the library fuzzywuzzy to match two string and get the following error message:

AttributeError: module 'fuzzywuzzy' has no attribute 'ratio'

Has the version changed? I tried to look for other functions within fuzz to see if it exists, but I am unable to find it.

import fuzzywuzzy as fuzz
from fuzzywuzzy import process
import Levenshtein
fuzz.ratio('Lord of the Rings', 'The Lord of the Rings')
petezurich
  • 9,280
  • 9
  • 43
  • 57
sharp
  • 2,140
  • 9
  • 43
  • 80

4 Answers4

5

ratio is a method of fuzzywuzzy.fuzz. Use:

from fuzzywuzzy import fuzz

Then you can use:

fuzz.ratio('Lord of the Rings', 'The Lord of the Rings')
Jab
  • 26,853
  • 21
  • 75
  • 114
2

If you check here, you can see that you are not importing fuzzywuzzy correctly.

Instead of import fuzzywuzzy as fuzz you should use from fuzzywuzzy import fuzz

Basically, you have two ways to do it. Either:

import fuzzywuzzy as <something>
<something>.fuzz.ratio(...)

or from fuzzywuzzy import fuzz fuzz.ratio(...)

Granny Aching
  • 1,295
  • 12
  • 37
2

Change import to:

from fuzzywuzzy as fuzz
from fuzzywuzzy import process
kosist
  • 2,868
  • 2
  • 17
  • 30
0

The readme file over at https://github.com/seatgeek/fuzzywuzzy states that the way to use fuzzywuzzy is:

from fuzzywuzzy import fuzz
from fuzzywuzzy import process

The way you have done it (import fuzzy-wuzzy as fuzz) means you would need another level in your calling hierarchy, fuzz.fuzz.blah instead of just fuzz.blah.

So the answer is to either use that extra level, or import it in the documented manner.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953