2

I created an exe for my script using Pyinstaller and while running the exe it throws the following error where as if I run the .py file no issues found.

Traceback (most recent call last):
  File "myApplication.py", line 12, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
  File "dataframe_image\__init__.py", line 2, in <module>
    """This directory is meant for IPython extensions."""
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
  File "dataframe_image\_pandas_accessor.py", line 2, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
  File "pandas\io\formats\style.py", line 64, in <module>
  File "pandas\io\formats\style.py", line 143, in Styler
  File "jinja2\environment.py", line 883, in get_template
  File "jinja2\environment.py", line 857, in _load_template
  File "jinja2\loaders.py", line 115, in load
  File "jinja2\loaders.py", line 249, in get_source
jinja2.exceptions.TemplateNotFound: html.tpl
[18152] Failed to execute script myApplication

Here, [File "myApplication.py", line 12, in ] is "import dataframe_image as dfi" in my script.

I don't use jinja2 module directly in my script.

I tried the build option, --hidden-import=dataframe_image, it doesn't work for this issue.

Pyinstaller=4.3 Python=3.7.7

Thank you for your help in advance!

[updates on 21th Apr.]

The solution, pyinstaller --add-data path-to-site-packages\pandas\io\formats\templates\html.tpl;pandas\io\formats\templates solved above error but another error arose.

Exception in Tkinter callback
Traceback (most recent call last):
  File "tkinter\__init__.py", line 1705, in __call__
  File "myApplication.py", line 374, in main
  File "dataframe_image\_pandas_accessor.py", line 24, in export
  File "dataframe_image\_pandas_accessor.py", line 33, in _export
  File "dataframe_image\_screenshot.py", line 79, in __init__
  File "dataframe_image\_screenshot.py", line 86, in get_css
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\***\\AppData\\Local\\Temp\\_MEI252882\\dataframe_image\\static\\style.css'

Here, File "myApplication.py", line 374, in main is dataframe_image.export(style, 'myTable.png')

dyossy
  • 23
  • 1
  • 5

1 Answers1

1

This is problem with how pandas templates are included with the bundle. There are two issues reported with pandas dev team:

and one reported with pyinstaller team:

Check this answer from pyinstaller team: https://github.com/pyinstaller/pyinstaller/issues/5360#issuecomment-737197845

If it doesn't work for you check this answer to resolve the issue:

It's not the best, because requires to edit pandas code, but anyway.

buran
  • 13,682
  • 10
  • 36
  • 61
  • Thank you for your information. The solution, `pyinstaller --add-data path-to-site-packages\pandas\io\formats\templates\html.tpl;pandas\io\formats\templates` solved this error but another error arose. – dyossy Apr 21 '21 at 06:24
  • try the same for `static` folder for `dataframe_image` package e.g. `--add-data path-to-site-packages\dataframe_image\static\` – buran Apr 21 '21 at 06:33
  • It works and finally I could run my application with no error and get the result as expected! Thanks a lot!!! – dyossy Apr 21 '21 at 10:50