Python 生成后未显示数据库
我正在使用cx\u Freeze构建我的可执行文件。我使用Pyqt4和QtSql模块来显示我的数据库,问题是在运行python脚本时,会显示数据库,并且表工作正常,但当我将其作为可执行文件运行时,表工作不正常,并且不会显示任何内容。作为脚本运行时: 作为可执行文件运行时: 有什么原因吗?这是cx_冻结的错误吗 以下是我创建表的代码:Python 生成后未显示数据库,python,sqlite,pyqt,cx-freeze,qsqltablemodel,Python,Sqlite,Pyqt,Cx Freeze,Qsqltablemodel,我正在使用cx\u Freeze构建我的可执行文件。我使用Pyqt4和QtSql模块来显示我的数据库,问题是在运行python脚本时,会显示数据库,并且表工作正常,但当我将其作为可执行文件运行时,表工作不正常,并且不会显示任何内容。作为脚本运行时: 作为可执行文件运行时: 有什么原因吗?这是cx_冻结的错误吗 以下是我创建表的代码: self.ProductModel = QtSql.QSqlRelationalTableModel() self.ProductM
self.ProductModel = QtSql.QSqlRelationalTableModel()
self.ProductModel.setTable("Product")
self.ProductModel.setRelation(6, QtSql.QSqlRelation("ProductType","ProductTypeID","Type"))
self.ProductModel.select()
fields = ["Product ID", "Product Name", "In Stock", "Expiry Date", "Stock Alert", "Price", "Product Type"]
for count in range(len(fields)):
self.ProductModel.setHeaderData(count, QtCore.Qt.Horizontal, fields[count])
edit = QtSql.QSqlTableModel.OnManualSubmit
self.ProductModel.setEditStrategy(edit)
self.ProductView = QtGui.QTableView()
self.ProductView.setModel(self.ProductModel)
self.ProductView.setSelectionMode(self.mode)
self.ProductView.setItemDelegate(ProductDelegate())
self.ProductView.sortByColumn(0,QtCore.Qt.AscendingOrder)
self.ProductView.setSortingEnabled(True)
这应该没有什么问题,因为在脚本中一切都很好
下面是cx\U冻结的设置脚本代码:
from cx_Freeze import setup, Executable import sys import matplotlib
base = None if sys.platform == 'win32':
base = 'Win32GUI'
executables = [Executable("Main.py", base = base)] includes = ['matplotlib', 'PyQt4.QtSql'] setup(name = 'Test',
options = {"build_exe" : {"includes" : includes }},
version = '0.18',
description = 'Test',
executables = executables)
我一直在努力解决同样的问题,但在stackoverflow中的另一个问题上,我发现解决方案是将位于C:\Python34\Lib\site packages\PyQt5\plugins的文件夹sqldrivers复制到您的可执行目录中我怀疑QtSql使用一些插件与不同的数据库后端进行通信。如果插件在冻结过程中没有被复制,它将无法读取数据库。@ThomasK它确实连接并读取数据库,因为程序的另一部分对同一数据库使用sql查询工作正常,所以它不可能是连接问题。与另一个问题的链接是什么?确保将URL添加到您的答案中。