I wanted to use pyinstaller to make an EXE of this program which runs my react frontend.
It runs fine with I do it in my powershell as python3 main.py
. However, when I launch the main.exe it doesn’t work and gives me the error
The requested URL was not found on the server.
If you entered the URL manually please check your spelling and try again
Here’s the output from my cmd running the flask:
127.0.0.1 - - [18/Jun/2024 14:05:24] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [18/Jun/2024 14:05:24] "GET /favicon.ico HTTP/1.1" 404 -
How can I fix this?
Thank you
Here’s the code for my main.py
import webview
from flask import Flask, render_template, send_from_directory
# Initialize Flask application
app = Flask(__name__, static_folder="dist", static_url_path="")
# Serve the React frontend
@app.route("/")
def index():
return send_from_directory("dist", "index.html")
# Example API endpoint
@app.route("/api/data")
def get_data():
# Example: Return some data as JSON
return {"message": "Hello from Python API"}
def start_flask_app():
# Run Flask app on localhost:5001
app.run(host="localhost", port=5001)
def start_pywebview():
# Create Pywebview window
webview.create_window("My App", "http://localhost:5001", width=800, height=600)
webview.start()
if __name__ == "__main__":
import threading
# Start Flask app in a separate thread
flask_thread = threading.Thread(target=start_flask_app)
flask_thread.start()
# Start Pywebview in the main thread
start_pywebview()
My main.py is in a folder called dist which has my react front end after being built.