[英]How to make an executable python tkinter file with a connection to a sqlite3 database
I have made a simple CRUD database program like a very simple inventory system.我制作了一个简单的 CRUD 数据库程序,就像一个非常简单的库存系统。 It is able to read from database, update the database, delete things from database and etc. by doing queries to the SQLite3 database.
它能够通过对 SQLite3 数据库进行查询来从数据库中读取、更新数据库、从数据库中删除内容等。 Now, I would like to make it executable so that I could share it to users for them to try out the program.
现在,我想让它可执行,以便我可以将它分享给用户,让他们试用该程序。
By now, I have tried pyinstaller with such code: pyinstaller --onefile --add-data "database.db:." inventory.py
到目前为止,我已经用这样的代码尝试了 pyinstaller:
pyinstaller --onefile --add-data "database.db:." inventory.py
pyinstaller --onefile --add-data "database.db:." inventory.py
It successfully compiled the program.它成功编译了程序。 However, when I execute the executable file, comes an error in the terminal saying
sqlite3.OperationalError: no such table: items_list
and it immediately close the program.但是,当我执行可执行文件时,终端出现一个错误,
sqlite3.OperationalError: no such table: items_list
并立即关闭程序。
Here is the code inside the program for me to connect to the sqlite3 database:这是我连接到 sqlite3 数据库的程序中的代码:
db = sqlite3.connect('database.db')
cursor = db.cursor()
and for me to display the items in the treeview, I used:为了显示 treeview 中的项目,我使用了:
def update(rows):
tree.delete(*tree.get_children())
for i in rows:
tree.insert('', 'end', value=i)
...
query = 'SELECT ItemName, CardNo, StockCount FROM items_list'
cursor.execute(query)
rows = cursor.fetchall()
update(rows)
Is there a way where I could combine the.py file with the.db file and make an executable single program?有没有办法可以将 .py 文件与 .db 文件结合起来制作一个可执行的单个程序? Thank you very much in advance for your help!
非常感谢您的帮助!
I have written similar Inventory type scripts that all work with a sqlite database.我编写了类似的 Inventory 类型脚本,它们都适用于 sqlite 数据库。 All variables aside.
抛开所有变数。 I used
pyinstaller.exe --onefile --windowed
as command.我使用
pyinstaller.exe --onefile --windowed
作为命令。 When using Windows 10, it puts in in the C:\...\dist
directory.使用 Windows 10 时,放入
C:\...\dist
目录。 I copied the database to the same path as the .exe
file(s) with all imported scripts used in the .exe
file and it accesses the respective database accordingly.我将数据库复制到与
.exe
文件相同的路径,并在.exe
文件中使用了所有导入的脚本,并相应地访问相应的数据库。 Also basing it on other variables like to install the respective programs.还基于其他变量,例如安装相应的程序。 (I just did it to be sure I do not run into any issues regarding alpha testing.) Then also depending on when the code, updates the
.db
file accordingly. (我只是为了确保不会遇到任何关于 alpha 测试的问题。)然后还取决于代码何时相应地更新
.db
文件。 (This method worked for me when I encountered similar issues) (当我遇到类似问题时,这种方法对我有用)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.