简体   繁体   English

使用 Pyinstaller 创建单个 Flask 可执行文件

[英]Creating Single Flask executable file with Pyinstaller

I have created a flask application which runs on a local server.我创建了一个在本地服务器上运行的 flask 应用程序。 I need to turn it into a single executable file using pyinstaller.我需要使用 pyinstaller 将其转换为单个可执行文件。

The following is my directory structure for my flask application in PyCharm:以下是我在 PyCharm 中的 flask 应用程序的目录结构:

Form
- migrations
- venv
- - app
- - - static
- - - templates
- - - __init__.py
- - - forms.py
- - - models.py
- - - routes.py
- microform.py
- config.py
- app.db

I tried running我试着跑步

pyinstaller -w -F --add-data "C:\Users\test\PycharmProjects\Form\venv\app\templates;templates" 
--add-data "C:\Users\test\PycharmProjects\Form\venv\app\static;static" 
--add-data "C:\Users\test\PycharmProjects\Form\migrations;migrations" microform.py

Everything compiled properly, and the flask application works except for the database that I created.一切编译正确,除了我创建的数据库之外,flask 应用程序工作正常。 I am unable to login because but the flask application gives me the following error when I input my username and password:我无法登录,因为当我输入用户名和密码时,flask 应用程序给了我以下错误:

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) unable to open database file
(Background on this error at: http://sqlalche.me/e/e3q8)

Everything works fine when I run it in PyCharm, but when I try opening it by clicking on the executable file from pyinstaller it just gives me the above error whenever I try to login?当我在 PyCharm 中运行它时一切正常,但是当我尝试通过单击 pyinstaller 中的可执行文件打开它时,它只会在我尝试登录时出现上述错误?

Appreciate any help or advice.感谢任何帮助或建议。 Thanks.谢谢。

You should run the pyinstaller command with your main file, where you call all of your functions and classes.您应该使用您的主文件运行 pyinstaller 命令,您可以在其中调用所有函数和类。

You might check the following link:您可以查看以下链接:

https://datatofish.com/executable-pyinstaller/ https://datatofish.com/executable-pyinstaller/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM