V-Ghost
V-Ghost

Reputation: 69

Python .exe containing alive progress bar error (FileNotFound)

I converted my .py file which contains the alive progress bar package https://pypi.org/project/alive-progress/ into a .exe for windows using the pyinstaller command pyinstaller --console . I however receive an error when I run the program. It runs fine until the alive bar is called and then it prints out the error below.

Traceback (most recent call last):
  File "network_nodes_ping.py", line 38, in <module>
  File "alive_progress\core\progress.py", line 106, in alive_bar
  File "alive_progress\core\configuration.py", line 149, in create_context
  File "alive_progress\core\configuration.py", line 183, in lazy_init
  File "alive_progress\core\configuration.py", line 14, in _spinner_input_factory
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "alive_progress\styles\__init__.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "alive_progress\styles\exhibit.py", line 9, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "alive_progress\styles\internal.py", line 126, in <module>
  File "alive_progress\styles\internal.py", line 12, 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 145, in to_cells
  File "alive_progress\utils\cells.py", line 149, in split_graphemes
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "grapheme\__init.py", line 9, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "grapheme\api.py", line 2, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "grapheme\finder.py", line 3, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "grapheme\grapheme_property_group.py", line 97, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\BRYANV~1\\AppData\\Local\\Temp\\_MEI85082\\grapheme\\data/grapheme_break_property.json'
[13328] Failed to execute script 'network_nodes_ping' due to unhandled exception!

Upvotes: 1

Views: 2058

Answers (4)

Wick
Wick

Reputation: 1

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

Upvotes: 0

Vedant Desai
Vedant Desai

Reputation: 51

If you are using .spec file to generate exe - it's similar to what @Pluckerpluck said but you would need to include this file like this

datas=[(r"C:\Source\venv\Lib\site-packages\grapheme", "grapheme/")]

If you add this in your .spec file. It works.

Upvotes: 1

Maxim Pekurin
Maxim Pekurin

Reputation: 41

A shorter alternative to what @Pluckerpluck has suggested would be using --collect-data grapheme instead of --add-data <...>.

Upvotes: 4

Pluckerpluck
Pluckerpluck

Reputation: 731

alive-progress uses a library called grapheme. This library requires a JSON file which you will have to manually specify when using PyInstaller.

In my case, I had it under .venv so the command to make this work was:

pyinstaller -F --add-data ".\.venv\Lib\site-packages\grapheme\data\grapheme_break_property.json;grapheme\data" my_file.py

Note that the argument --add-data takes both a source and a target directory (which we set to grapheme\data)

I will warn you however, that the default terminal doesn't have the fonts capable of actually displaying the progress bar. It works, but it doesn't look pretty. If you run the .exe from a proper terminal though with the font support, it works just fine after this.

Upvotes: 1

Related Questions