rsalmei / alive-progress

A new kind of Progress Bar, with real-time throughput, ETA, and very cool animations!
MIT License
5.53k stars 206 forks source link

FileNotFoundError grapheme_break_property.json when built as executable with PyInstaller #123

Closed pranjal-joshi closed 2 years ago

pranjal-joshi commented 2 years ago

Hello, I am shipping executables with PyInstaller. Even though I've enabled hidden import for alive-progress/alive_progress, The executable throws the following error during runtime.

  File "PyInstaller/loader/pyimod03_importers.py", line 476, in exec_module
  File "alive_progress/styles/exhibit.py", line 9, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller/loader/pyimod03_importers.py", line 476, in exec_module
  File "alive_progress/styles/internal.py", line 144, in <module>
  File "alive_progress/styles/internal.py", line 22, in __create_spinners
  File "alive_progress/animations/spinners.py", line 43, in frame_spinner_factory
  File "alive_progress/animations/spinners.py", line 43, in <genexpr>
  File "alive_progress/animations/spinners.py", line 43, in <genexpr>
  File "alive_progress/utils/cells.py", line 144, in to_cells
  File "alive_progress/utils/cells.py", line 148, in split_graphemes
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller/loader/pyimod03_importers.py", line 476, in exec_module
  File "grapheme/__init__.py", line 9, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller/loader/pyimod03_importers.py", line 476, in exec_module
  File "grapheme/api.py", line 2, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller/loader/pyimod03_importers.py", line 476, in exec_module
  File "grapheme/finder.py", line 3, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller/loader/pyimod03_importers.py", line 476, in exec_module
  File "grapheme/grapheme_property_group.py", line 97, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/_MEIr3FD7j/grapheme/data/grapheme_break_property.json'
pranjal-joshi commented 2 years ago

Got it working by force downgrading the version to alive_progress==1.6.2

rsalmei commented 2 years ago

Yeah, maybe you could try to install the dependencies previously? grapheme and about-time.

pranjal-joshi commented 2 years ago

Closing this as of now because it's working with a downgraded version. But, I will keep you posted about the updates.

rsalmei commented 2 years ago

OK, here we are @m1ch4elx and @Mettwasser. Care to explain exactly what are you doing, which commands are you using, etc?

Mettwasser commented 2 years ago

OK, here we are @m1ch4elx and @Mettwasser. Care to explain exactly what are you doing, which commands are you using, etc?

So I'm only using alive_bar(). When using the newest version it drops that error (in the .exe - made with pyinstaller).

controlado commented 2 years ago

Hey! I'm getting that problem too, exactly this error... Any way to resolve that? Thank you! (:

rsalmei commented 2 years ago

Well, I don't know this PyInstaller, but I'm sure it is messing up grapheme install.

FileNotFoundError: [Errno 2] No such file or directory: '/tmp/_MEIr3FD7j/grapheme/data/grapheme_break_property.json'

Since grapheme cannot find a required file it installed, perhaps that file got misplaced, or not put into the exe at all. I did a quick look into it, and that seems exactly the case. Here it is: https://pyinstaller.readthedocs.io/en/v4.10/operating-mode.html#analysis-finding-the-files-your-program-needs So, just include manually that file and it should work.

TheTechRobo commented 2 years ago

Seems pretty odd to put a required file in /tmp.

pranjal-joshi commented 2 years ago

Is there any way to include grapheme using --hidden-imports while packaging with pyinstaller?

controlado commented 2 years ago

U have to run this pyi-makespec --onefile start.py in terminal with ur main.py file. After that, put that line in the spec file after a block code:

a.datas += Tree("<python_path>/Lib/site-packages/grapheme/", prefix= "grapheme") a.datas += Tree("<python_path>/lib/site-packages/about-time/", prefix= "about-time")

Like that:

a = Analysis(['script.py'],
             pathex=[],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
a.datas += Tree("<python_path>/Lib/site-packages/grapheme/", prefix= "grapheme")
a.datas += Tree("<python_path>/lib/site-packages/about-time/", prefix= "about-time")

Then, run pyinstaller spec file and that's it!

rsalmei commented 2 years ago

You didn't understand @TheTechRobo. In order for this PyInstaller to run the exe, it seems to need to unzip all files it packed in a temp directory. Then, when grapheme ran, it tried to read an internal file that should be there, in its data dir, but the exe didn't include it... This is the error.

rsalmei commented 2 years ago

Anyway, thanks @balasclava! It should be right on what you've sent! I see you've told it include both grapheme and about-time, which should cover everything 👍 Actually, since about-time is also a project of mine, I'm sure it doesn't use any additional files, so it should be fine to remove that line.

I'm just waiting now for someone to confirm it works to close this, thanks!!

stevenzieske commented 2 years ago

Hello everyone, for me the solution of @balasclava works! Although i could not use the following path "/lib/site-packages/about-time/" . For me, the folder was named with an underscore "/lib/site-packages/about_time/".

Thank you very much for the help.

rsalmei commented 2 years ago

I'm glad it worked, thanks!

xinxin8816 commented 2 years ago

CLI Just add grapheme data like pyinstaller -F "Hello World.py" --collect-all grapheme