开发者

PyQT can't find any SQL drivers

I'm developing a PyQT application and want to use a SQL database. The engine doesn't matter that much. And I have a working MySQL installed in my system (I use it frequently), and also the SQLite3 DLL is present, by default in my system32 folder, and I have also put a copy beside qsqlite dll.

But when I call

db = QtSql.QSqlDatabase.addDatabase("QSQLITE")

or

db = QtSql.QSqlDatabase.addDatabase("QMYSQL")

All I 开发者_如何学Cget is:

QSqlDatabase: QSQLITE driver not loaded
QSqlDatabase: available drivers:

No Drivers at all. What should I do? Thanks in advance.


I use PySide to develop application with Python 3.3. I also encounter the same problem, and I have a workaround.

I found that if QApplication() is called before QtSql.QSqlDatabase.addDatabase('QSQLITE'), the problem is gone.

Finally, I try the method to place the following codes before addDatabase and the problem is solved

site_pack_path = site.getsitepackages()[1]
QtGui.QApplication.addLibraryPath('{0}\\PySide\\plugins'.format(site_pack_path))

ps. check that the "sqldrivers" folder is in 'plugins' folder


I don't speak english very well.

I use Python 2.7 under windows 10, Postgresql, and developt the gui in QT , use PyQt4 and QtSql. And use spyder. (In reality everything is included in Python ( x , y))

,-) but here is the easy solution. Open the file C:\Python27\qt.conf, First I had inside the file this lines:

Prefix = C:/Python27/Lib/site-packages/PyQt4
Binaries = C:/Python27/Lib/site-packages/PyQt4

then you add the next lines:

Plugins = C:/Python27/Lib/site-packages/PyQt4/plugins
Translations = C:/Python27/Lib/site-packages/PyQt4/translations

Make sure that the plugins are in C:/Python27/Lib/site-packages/PyQt4/plugins. Then close python and open again. Then all work perfectly. You found the same answer here http://www.voidynullness.net/blog/2013/01/24/pyqt-database-driver-loading-issues-on-windows-after-installing-pyside/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜