Python 将flask web应用程序转换为独立的可执行桌面应用程序

Python 将flask web应用程序转换为独立的可执行桌面应用程序,python,flask,flask-sqlalchemy,pyinstaller,Python,Flask,Flask Sqlalchemy,Pyinstaller,我正在尝试使用Pyinstaller将flask web应用程序导出到一个独立的可执行文件,以便在本地主机上运行,但在打包数据库文件时遇到问题 我的项目结构: /project /app __init__.py # This is where I call the app.run() method routes.py forms.py config.py /database

我正在尝试使用Pyinstaller将flask web应用程序导出到一个独立的可执行文件,以便在本地主机上运行,但在打包数据库文件时遇到问题

我的项目结构:

/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

在/project/app/I中,我正在使用以下命令运行Pyinstaller:

pyinstaller -F --add-data "templates;templates" --add-data "database;database" __init__.py
执行上述命令后,尝试运行生成的exe文件失败,控制台上出现以下错误:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file
在config.py中,我有一个名为config的类,在该类中我将db URI定义为:

SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join('database', 'data.db')
我认为问题在于实际的打包,因为在pycharm中或从命令行运行应用程序不会有任何问题

非常感谢您对这个问题的帮助,非常感谢

如果您没有使用--onefile,pyinstaller应该生成一个目录(名为“dist”IIRC)。它包含你的数据库吗?