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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Mike IT Expert
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


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
Reply | Threaded
Open this post in threaded view
|

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

michael h

Any comment i s mcuh appreciate it.

Thanks 
Mike


_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt



Do you have libmysqlclient.so available? maybe use strace or ltrace to see where the loading fails.

_______________________________________________
PyQt mailing list    [hidden email]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt