LBeaudoux / iso639

A fast, simple ISO 639 library.
MIT License
32 stars 4 forks source link

Exception raised after compiling with pyinstaller #11

Closed VXsz closed 2 years ago

VXsz commented 2 years ago

After compiling with pyinstaller I keep getting this error:

test\dist>test.exe
Traceback (most recent call last):
  File "test.py", line 2, in <module>
  File "iso639\iso639.py", line 68, in __new__
iso639.exceptions.InvalidLanguageValue: (*('ja',), **{}). Only valid ISO 639 language values are supported as arguments.
[10072] Failed to execute script 'test' due to unhandled exception!

Not sure why, perhaps I need to add some data with pyinstaller but I feel like it won't help since that's not the issue I think here My guess would be some args passing issue (probably)

my original python code is simply these lines

from iso639 import Lang
print(Lang('ja').name)

then compiled using pyinstaller (installed through pip) with this command: pyinstaller test.py --onefile

LBeaudoux commented 2 years ago

I am not familiar with pyinstaller but it seems to me that you have to add the necessary .json and .pkl data files found in iso639/data/ to your bundle as explained here.

The iso639.exceptions.InvalidLanguageValue exception is misleading. It is raised because preceding FileNotFoundError exceptions are caught in the iso639.datafile module when the loading of mappings fails (which in retrospect seems like a bad idea).

VXsz commented 2 years ago

I see, after a bit of trying --add-data "C:\Users\<user>\AppData\Local\Programs\Python\Python39\Lib\site-packages\iso639;./iso639" worked perfectly

Also thank you so much for this library, it saved me a lot of headaches & a huge amount of time

jessielw commented 7 months ago

I know this is old, but I put in a PR to pyinstallers hooks contrib here https://github.com/pyinstaller/pyinstaller-hooks-contrib/pull/707