构建后数据库未显示

时间:2015-03-11 18:34:07

标签: python sqlite pyqt cx-freeze qsqltablemodel

我使用cx_Freeze构建我的可执行文件。我使用Pyqt4和QtSql模块来显示我的数据库,问题是当运行python脚本时,显示数据库并且表工作正常但是当我将其作为可执行文件运行时表不能正常工作并且不显示任何内容。以脚本形式运行时:When Run Using Python Script 作为可执行文件运行时:When running as an executable 有什么理由为什么?这是cx_Freeze的一些错误吗?

以下是我创建表格的代码:

        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_Freeze的设置脚本代码:

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)

1 个答案:

答案 0 :(得分:0)

我正在努力解决同样的问题,但在另一个问题上(这里是stackoverflow)我发现解决方案是将文件夹sqldrivers(我的C:\ Python34 \ Lib \ site-packages \ PyQt5 \ plugins)复制到你的可执行目录

相关问题