Search code examples
flaskpyinstaller

Internal Error when using PyInstaller to make an standalone app using Flask + FlaskWebGui


Ok so I've been trying to make a standalone python app using Flask and FlaskWebGUI, it works just fine when I'm running it on VScode, print of an example program below:

enter image description here

Working just fine, ok. But when I use the PyInstaller command pyinstaller server.py to create the desktop app for some reason this following error occurs:

enter image description here

that's my server.py code:

from flask import Flask, render_template, request, redirect, url_for
#importa o Web GUI
from flaskwebgui import FlaskUI


app = Flask(__name__)
app.static_folder = 'static'

ui = FlaskUI(app, width=1150, height=700)
 
# A decorator used to tell the application
# which URL is associated function
@app.route('/', methods =["GET", "POST"])
def gfg():
    if request.method == "POST":
       # getting input with name = fname in HTML form
       first_name = request.form.get("fname")
       # getting input with name = lname in HTML form
       last_name = request.form.get("lname")
       return "Your name is "+first_name + last_name
    return render_template("index.html")

# runs app
if __name__ == "__main__":

    # app.run(debug=True)

    # Default start flask
    FlaskUI(
            app=app,
            server="flask",
            width=1150,
            height=700,
        ).run()

I have no idea why it isn't working.

In case it's useful, here's the PyInstaller log after running the command: https://pastebin.com/6dC6fTBs

==========

I also have tried using the following PyInstaller commands:

pyinstaller --name myapp --onefile server.py -> still not working

pyinstaller --name myapp --onefile --add-data "templates;." server.py -> also not working


Solution

  • It was a dependent files issue, PyInstaller you need to specify the dependency files to PyInstaller and I just wasn't managing to do it.

    I then instead of typing the PyInstaller command by myself, i used it's GUI (by running "auto-py-to-exe" on a terminal in the script folder) then i used the GUI to select the dependency files (I did not had to select libraries manually, just files like .html, .png) and it worked just fine.

    There's also a lot of other configs you can set using the GUI, but that's all i needed to make the program run properly.