QtSQL - QMYSQL driver not loaded (Ubuntu)

2019-08-07 21:09发布

I want to access a SQL database via PyQt4 on Ubuntu. I already installed apt-get install python-qt4-sql but when I add a Database like this:

import sys
from PyQt4 import QtGui, QtCore, QtSql

appcore = QtCore.QCoreApplication(sys.argv)

db = QtSql.QSqlDatabase.addDatabase('QMYSQL')
db.setHostName('localhost')
db.setDatabaseName('database1')
db.setUserName('root')
db.setPassword('root')

if db.open() == False:
    print 'fail'

I get the error

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE

How can I load the driver QMYSQL?

1条回答
放我归山
2楼-- · 2019-08-07 21:56

I could fix the problem by installing apt-get install libqt4-sql-mysql.

查看更多
登录 后发表回答