autocorrect icon indicating copy to clipboard operation
autocorrect copied to clipboard

Crash when using autocorrect library from pyinstaller .exe file

Open JustinLin905 opened this issue 5 years ago • 5 comments

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?

JustinLin905 avatar Dec 30 '20 21:12 JustinLin905

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

filyp avatar Dec 31 '20 02:12 filyp

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!

JustinLin905 avatar Dec 31 '20 16:12 JustinLin905

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.

filyp avatar Jan 03 '21 15:01 filyp

Any update on this?

JoshSilver8 avatar Apr 21 '23 17:04 JoshSilver8

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

David-Baron avatar Dec 11 '23 11:12 David-Baron