QtSQL - QMYSQL driver not loaded (Ubuntu)

烂漫一生 提交于 2019-12-11 08:43:58

问题


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:


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



来源:https://stackoverflow.com/questions/25792955/qtsql-qmysql-driver-not-loaded-ubuntu

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