0

I'm using cx_Freeze to build my executable. I used Pyqt4 and the QtSql modules to display my database, the problem is when running through the python script, the database is displayed and the table works fine but when i run it as an executable the table does not work properly and nothing is displayed. When running as script: When Run Using Python Script When running as an executable: When running as an executable Any reason as to why? Is this some bug for cx_Freeze?

Here is my code for creating the table:

        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)

There should be nothing wrong with this as everything works fine during the script.

and here's the setup script code for 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)
4

1 回答 1

0

我在同一个问题上苦苦挣扎,但在另一个问题上(在 stackoverflow 中)我发现解决方案是将文件夹 sqldrivers(我的位于 C:\Python34\Lib\site-packages\PyQt5\plugins)复制到您的可执行目录中

于 2016-06-07T23:00:28.833 回答