title: Flask app packaged with PyInstaller with no templates nor static included in EXE
body: <p>I´m trying to pack my <code>run.py</code> app into <code>run.exe</code>, but not including html <code>templates</code> and the <code>static</code> folder files in the .exe file, so they can be easily changed and updated without the need to recompile the .exe file.</p>
  <p>The app structure is:</p>
  <pre><code> run.py
     /serversystem
        /templates
        /static
        /main
        /users
  </code></pre>
  <p>In &quot;main&quot; and &quot;users&quot; folders there are empty <code>__init__.py</code> files, and <code>routes.py</code> files with the actual code, in a Blueprint architecture.</p>
  <p>I am using <code>pyinstaller --onefile run.py</code> and copying the packaged <code>dist\run.exe</code> file to the root folder where <code>run.py</code> lives.</p>
  <p>The error I get is that Jinja cannot find the template when I tell it to render it. This is from <code>http://localhost:3000/about</code>:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\flask\app.py&quot;, line 2091, in __call__
      
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\flask\app.py&quot;, line 2076, in wsgi_app
      
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\flask\app.py&quot;, line 2073, in wsgi_app
      
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\flask\app.py&quot;, line 1518, in full_dispatch_request
      
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\flask\app.py&quot;, line 1516, in full_dispatch_request
      
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\flask\app.py&quot;, line 1502, in dispatch_request
      
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\serversystem\main\routes.py&quot;, line 17, in about
      
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\flask\templating.py&quot;, line 148, in render_template
      
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\jinja2\environment.py&quot;, line 1068, in get_or_select_template
      
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\jinja2\environment.py&quot;, line 997, in get_template
      
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\jinja2\environment.py&quot;, line 958, in _load_template
      
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\jinja2\loaders.py&quot;, line 125, in load
      
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\flask\templating.py&quot;, line 59, in get_source
      
    File &quot;C:\Users\GP\AppData\Local\Temp\_MEI171402\flask\templating.py&quot;, line 95, in _get_source_fast
      
  jinja2.exceptions.TemplateNotFound: about.html
  </code></pre>
  <p>The same code works well in the IDE.</p>
  <p>I have added a chunk of code to <code>/systemserver/__init__.py</code> that goes:</p>
  <pre><code>def create_app(config_class=Config):
   if getattr(sys, 'frozen', False):
       print(&quot;Starting in FROZEN Mode&quot;)
   else:
       print(&quot;Starting in NORMAL Mode&quot;)
  
   app = Flask(__name__)
  
   print(&quot;Instance Path   = {}&quot;.format(app.instance_path))
   print(&quot;Root Path       = {}&quot;.format(app.root_path))
   print(&quot;Templates Path  = {}&quot;.format(app.template_folder))
   print(&quot;Static Path     = {}&quot;.format(app.static_folder))
   print(&quot;Static URL Path = {}&quot;.format(app._static_url_path))
  </code></pre>
  <p>When running from IDE (VSCode), I get this:</p>
  <pre><code>Starting in NORMAL Mode
  Instance Path   = h:\MyProject\Alfa1D\instance
  Root Path       = h:\MyProject\Alfa1D\serversystem
  Templates Path  = templates
  Static Path     = h:\MyProject\Alfa1D\serversystem\static
  Static URL Path = None
  </code></pre>
  <p>When running from exe file, this is the output:</p>
  <pre><code>Starting in FROZEN Mode
  Instance Path   = C:\Users\GP\AppData\Local\Temp\_MEI144962\var\serversystem-instance
  Root Path       = C:\Users\GP\AppData\Local\Temp\_MEI144962\serversystem
  Templates Path  = templates
  Static Path     = C:\Users\GP\AppData\Local\Temp\_MEI144962\serversystem\static
  Static URL Path = None
  </code></pre>
  <p>As I haven´t used the <code>template_folder=template_folder, static_folder=static_folder</code> options when creating the Flask app, the template and static files do not get packed so they don´t go to the temp MEI folder.</p>
  <p>Is it possible to pack the EXE file and, when running it from where run.py is, make it use the template &amp; static files from the fixed folders and not the temp one?</p>
  <p>I use Python 3.10 and PyInstaller 4.7, on Windows 10.</p>