简体   繁体   English

如何使用连接到 sqlite3 数据库的可执行 python tkinter 文件

[英]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.

相关问题 是否可以将 python 代码与 tkinter 和 sqlite3 数据库 package 捆绑到 exe 可执行文件 - Is it possible to bundle python code with tkinter and sqlite3 database package to an exe executable file Python 程序在可执行文件中不起作用 - 归档、sqlite3、tkinter - Python programme not working in executable file - archiving,sqlite3, tkinter 加密/隐藏 sqlite3 数据库(Tkinter 和 Python) - Encrypt/Hide sqlite3 database (Tkinter & Python) 如何在Python中获得到加密数据库的SQLite3连接 - How do you get a SQLite3 connection to an encrypted database in Python Python。 如何将 sqlite3 数据库转换为 Excel 文件 - Python. How to convert a sqlite3 database into an Excel file 如何在Python中使用sqlite3连接 - How to use an sqlite3 connection in Python 无法使用 python 访问 sqlite3 数据库文件 - Cannot access an sqlite3 database file with python Python和sqlite3-将文本文件导入数据库 - Python and sqlite3 - import text file into database 如何使用tkinter Python创建搜索表单以从SQLITE3数据库进行搜索? - How to create search form using tkinter Python to search from the SQLITE3 Database? 如何在 Python 中使用 GUI Tkinter 以特定格式显示来自数据库 sqlite3 的信息? - How to display information from database sqlite3 using GUI Tkinter in Python in a specific format?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM