[PyQt] [PyQt5 Python 3.6 MySql] QSqlDatabase: QMYSQL driver not loaded

Mike IT Expert mikeitexpert at gmail.com
Sat Jun 23 19:22:35 BST 2018


Hi All,

I have installed PyQt5 (on Python 3.6) on my Ubuntu 18.04 machine it works
just find with SQLite database files. But If I try the below code I get the
following error:



from PyQt5.QtSql import QSqlDatabase, QSqlQuery, QSqlTableModel
from PyQt5.QtWidgets import QTableView, QApplication
import sys
app = QApplication(sys.argv)
db = QSqlDatabase.addDatabase('QMYSQL')
db.setHostName('127.0.0.1')
db.setDatabaseName('ZZZ')
db.setUserName('YYY')
db.setPassword('XXX')
ok = db.open()
if not ok: print(db.lastError().text())
else: print("connected")
query = QSqlQuery(db);
query.exec_('SELECT * FROM tbl_Customers');




QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QPSQL QPSQL7
Driver not loaded Driver not loaded



I just checked to see where the sql driver comes for SQLite database and I
found:


$ find /usr/local/lib/python3.6/dist-packages/PyQt5 -iname "*sqlite*"
/usr/local/lib/python3.6/dist-packages/PyQt5/Qt/plugins/sqldrivers/libqsqlite.so


so if I list the content of the above directory it looks like the below:

*$ ls /usr/local/lib/python3.6/dist-packages/PyQt5/Qt/plugins/sqldrivers/*
*libqsqlite.so  libqsqlmysql.so  libqsqlpsql.so*


So it seems to me that the driver is installed but for some reason it is
not picked by PyQt5. Please let me know if you have any commnets.

Any comment i s mcuh appreciate it.

Thanks
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180623/7b2d9f7d/attachment-0001.html>


More information about the PyQt mailing list