filyp / autocorrect

Spelling corrector in python
GNU Lesser General Public License v3.0
447 stars 79 forks source link

Crash when using autocorrect library from pyinstaller .exe file #19

Open JustinLin905 opened 3 years ago

JustinLin905 commented 3 years ago

There is currently an issue which causes .exe files created using pyinstaller to crash.

If the source Python file used the autocorrect library, the program would crash if the user tried to launch it from the .exe file. "dictionary for this language not found, downloading..." will appear in the terminal, then "couldn't download https://drive.google.com/uc?export=download&id=19xqFyk9d8aFR7LR43oy6cExk8Pk9wVwV, trying next url...", followed by a ConnectionError: [Errno 2]. When I visit the link in my browser, it seems to work. This is for the English language.

Is it possible to fix this, or is the library not meant to be used from a stand-alone executable?

filyp commented 3 years ago

I never tried to make it usable from a stand-alone executable, but it would be a good feature. It seems that it's a problem with dictionary data that autocorrect needs, but pyinstaller cannot automatically bundle. Autocorrect looks for a file data/{lang}.tar.gz and if it doesn't exist it will try to download it: https://github.com/fsondej/autocorrect/blob/bda610212a77a193df5b5defe5c7f79a10f1e5e1/autocorrect/__init__.py#L34

First, you can try to make a directory data and put there en.tar.gz downloaded from that URL. This data directory should be in the same directory as your executable. If that works you can try to bundle that file, so you won't need additional directory. You can do it with pyinstaller's --add-data option https://stackoverflow.com/questions/41870727/pyinstaller-adding-data-files

JustinLin905 commented 3 years ago

Thanks for your response! Unfortunately, making a data directory with en.tar.gz inside did not fix the crash. My program still attempts to download the dictionary data.

Hopefully a stand-alone .exe with autocorrect will be possible sometime in the future!

filyp commented 3 years ago

Hmm, it looks that finding location works differently in stand-alone exe than in python file. We could add option in Speller.__init__ to give dictionary location manually https://github.com/fsondej/autocorrect/blob/bda610212a77a193df5b5defe5c7f79a10f1e5e1/autocorrect/__init__.py#L73 and later bundle those files using pyinstaller's --add-data option.

Unfortunately, I don't have time to do this now, but this should work.

JoshSilver8 commented 1 year ago

Any update on this?

David-Baron commented 8 months ago

Wouldn't the crash come from broken links to the "backup_urls" files?