Converting flask web app to a standalone executable desktop app

Viewed 1060

I am trying to export a flask web application to a standalone executable to run on localhost using Pyinstaller, I am having issues with packing the database file.

My project structure:

/project
    /app
        __init__.py    #    This is where I call the app.run() method
        routes.py
        forms.py
        config.py

        /database
            models.py
            data.db    #    sqlalchemy db file

        /files    #    Folder that stores temporary files
        /templates    #    HTML files

    /backend
        __init__.py
        module1.py
        module2.py

Within /project/app/ I am running Pyinstaller with the command:

pyinstaller -F --add-data "templates;templates" --add-data "database;database" __init__.py

After executing the above command, trying to run the exe file that was produced fails with the following error on console:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file

in config.py I have a class called Config in which I define the db URI as such:

SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join('database', 'data.db')

I believe the problem is with the actual packing, because running the app in pycharm or from command line works with no problems.

Would really appreciate help with this problem, thanks very much in advance!

0 Answers
Related