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)
Inthu
  • 1,009
  • 1
  • 8
  • 16
  • I suspect QtSql uses some plugins to talk to different database backends. If the plugins aren't getting copied in the freeze process, it won't be able to read the database. – Thomas K Mar 12 '15 at 18:59
  • @ThomasK Well it does connect and reads the database fine as another part of the program which uses sql queries to the same database is working fine, so it can't be a connection problem – Inthu Mar 12 '15 at 19:18

1 Answers1

0

I was struggling with the same issue, but on another question (here in stackoverflow) I found the solution is copying the folder sqldrivers (mine was at C:\Python34\Lib\site-packages\PyQt5\plugins) into your executable directory