[Python] PyInstaller + Flask; Bundled static and templates with .exe but need filepath for...

Discussão em 'Python' iniciado por Stack, Maio 13, 2025.

  1. Stack

    Stack Membro Participativo

    I'm new to using PyInstaller but I found this guide: https://elc.github.io/posts/executable-flask-pyinstaller/

    to create a .exe from my Flask app. It executed fine, and judging from the file size, it has successfully bundled all of my static files, however when running the .exe I get an error that it can't find the ./static directory, unless I move it to the same directory as my app.py at which point it works fine.

    Presumably this is something I need to change with the file paths in my Python code (as there are references to the ./static/assets/ filepath with os.listdir), not really sure what I need to change them to though. Alternatively, is it best just to leave the static files etc. out of my PyInstaller and put them in the directory?

    pyinstaller -w -F --add-data "templates;templates" --add-data "static;static" app.py Expected bundled app, instead getting errors that it can't find files.

    Continue reading...

Compartilhe esta Página