2

my python application looks like:

test.py

from PyQt4 import QtCore
from PyQt4 import QtGui
from PyQt4 import QtSql

import sys
import atexit

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    db = QtSql.QSqlDatabase.addDatabase('QODBC')
    sys.exit(app.exec_())

If i run this application, everything works fine. However, if I create an executable with cx_freeze, I always get the following error:

QSqlDatabase: QODBC driver not loaded

QSqlDatabase: available drivers:

I use the following command to create the executable:

C:\Python27\Scripts\cxfreeze.bat test.py --target-dir C:\Test --include-path="C:\Python27\Lib\site-packages\PyQt4"

If I look into C:\Test (the location where cx_freeze created the executable), I see a bunch of *.dll files with the word 'sql' in it (qsqlodbc4.dll, QtSql4.dll...)

In the past, I created a few PyQT applications with cx_freeze and it always worked really well. However together with the QtSql module, I always get the error message above.

My operating system: Windows 7

Do you guys have any ideas on how to resolve the problem?

edit: Okay, I got it. I copied the contents of PyQt4\plugins\sqldrivers to C:\Test\sqldrivers and now it works.

Kind Regards

Bernhard

user2494129
  • 717
  • 2
  • 13
  • 24
  • 2
    Thanks, I've [filed an issue](https://bitbucket.org/anthony_tuininga/cx_freeze/issue/65/add-hook-for-qtsql) to copy the plugins automatically when QtSql is used. – Thomas K Feb 18 '14 at 20:08
  • THANK YOU! I just had the same issue. And even though all the files were automatically copied into the right folder by cx_freeze and had the right sizes, manually overwriting them with the original files solved the problem! (Maybe you should add your solution as an answer and accept it, so it's easier to see and can be upvoted?) – CodingCat Jan 22 '19 at 09:18

1 Answers1

0

This woks only in your developer machine, but when you create a exe file and run this file in other machine it didn't work.

I use pyinstaller, and solve the problem.

only use:

pyinstaller --onefile --windowed myscript.py
Gabriel Asqui
  • 305
  • 3
  • 17