barrust / pyspellchecker

Pure Python Spell Checking http://pyspellchecker.readthedocs.io/en/latest/
MIT License
714 stars 164 forks source link

An error with python2.7: ValueError: Invalid mode ('rtb') #41

Closed limengmingx closed 5 years ago

limengmingx commented 5 years ago

I try the testing code:

from spellchecker import SpellChecker

spell = SpellChecker()

an get the error as below :

Traceback (most recent call last):
  File "1.py", line 4, in <module>
    spell = SpellChecker()
  File "C:\Python27\lib\site-packages\spellchecker\spellchecker.py", line 43, in __init__
    self._word_frequency.load_dictionary(full_filename)
  File "C:\Python27\lib\site-packages\spellchecker\spellchecker.py", line 327, in load_dictionary
    with load_file(filename, encoding) as data:
  File "C:\Python27\lib\contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "C:\Python27\lib\site-packages\spellchecker\utils.py", line 27, in load_file
    with gzip.open(filename, mode="rt") as fobj:
  File "C:\Python27\lib\gzip.py", line 34, in open
    return GzipFile(filename, mode, compresslevel)
  File "C:\Python27\lib\gzip.py", line 94, in __init__
    fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb')
ValueError: Invalid mode ('rtb')

The pyspellchecker is installed by : pip install pyspellchecker

limengmingx commented 5 years ago

Finally, I fixed the error with changing the /spellchecker/utils.py line 27:

        with gzip.open(filename, mode="rb") as fobj:
            yield fobj.read()
barrust commented 5 years ago

Sorry I hadn't been able to get to this until now, but what version of pyspellchecker are you using?

limengmingx commented 5 years ago

pyspellchecker 0.4.0 I installed it with command pip install pyspellchecker