1

I am trying to make a distributable of a flask application. Everything works fine when running locally. When an executable is generated with pyinstaller it gives me the error:

 Traceback (most recent call last):
  File "site-packages\flask\app.py", line 2446, in wsgi_app

  File "site-packages\flask\app.py", line 1951, in full_dispatch_request
  File "site-packages\flask\app.py", line 1820, in handle_user_exception
  File "site-packages\flask\_compat.py", line 39, in reraise
  File "site-packages\flask\app.py", line 1949, in full_dispatch_request
  File "site-packages\flask\app.py", line 1935, in dispatch_request
  File "app.py", line 39, in index
  File "site-packages\flask\templating.py", line 140, in render_template
  File "site-packages\flask\templating.py", line 120, in _render
jinja2.exceptions.TemplateNotFound: bootstrap/base.html

I am using the flask bootstrap as shown here.

yanarp
  • 165
  • 8
  • 1
    please refer this SO answer https://stackoverflow.com/questions/35811448/pyinstaller-jinja2-templatenotfound/36160856#36160856 – rsb Nov 21 '19 at 09:23

1 Answers1

2

create a new python file named 'hook-flask_bootstrap.py', inside of this paste the following:

from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('flask_bootstrap')

Now when you run pyinstaller provide the path to this 'hook-flask_bootstrap.py' file:

--additional-hooks-dir=PATH (If relative path, just use .)
Tristin
  • 21
  • 2
  • Thank you for your answer. I later decided not to use the flask bootstrap and designed the webpage using bootstrap in HTML. Although I did not test this, I hope this works for someone who comes here. – yanarp May 13 '20 at 22:40
  • 1
    I tried this, and it worked for me. Thanks Tristin. – Mr. Blonde Dec 04 '20 at 13:19