cx_freeze: QODBC driver not loaded

冷暖自知 提交于 2019-12-11 02:39:18

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/21791868/cx-freeze-qodbc-driver-not-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!