0

I am running python 2.7.3 (python-2.7.3.amd64.msi) from http://www.python.org/getit/

I am using these installers from: http://www.lfd.uci.edu/~gohlke/pythonlibs/

  • PyQt-Py2.7-x64-gpl-4.9.6-1.exe
  • PySide-1.1.2.win-amd64-py2.7.exe
  • MySQL-python-1.2.4.win-amd64-py2.7.exe

I also tried the pyqt and pyside binaries from:

I am getting the error "QSqlDatabase: QMYSQL driver not loaded" in the following python code. My best guess is that the pyside and pyqt binary installers above did not build qt to include QMYSQL? Can anyone confirm that AND more importantly, direct me to an installer that has the QMYSQL driver built? I am not prepared to attempt compiling the qt library myself. Any help is appreciated.

import sys

from showrec import *    # import qtdesigner ui (converted using pyside-uic)

from PySide import QtGui, QtSql

#===================================================================
# 
#===================================================================

def createConnection():

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

    db.setHostName('localhost')
    db.setDatabaseName('mydatabase')
    db.setUserName('userid')
    db.setPassword('password')
    db.open()
    print (db.lastError().text())
    return True

#===================================================================
#
#===================================================================

class MyForm(QtGui.QDialog):

    def __init__(self, parent=None):

        #super(MyForm, self).__init__(parent)   # I suspect this is needed?

        QtGui.QWidget.__init__(self,parent)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)

        self.model = QtSql.QSqlDatabase(self)
        self.model.setTable("products")
        self.model.setEditStrategy(QtSql.QSqlTableModel.OnManualSubmit)
        self.model.select()
        self.ui.tableView.setModel(self.model)

#===================================================================
# main
#===================================================================

if __name__ == "__main__":

    app = QtGui.QApplication(sys.argv)

    if not createConnection():
        sys.exit(1)

    myapp = MyForm()
    myapp.show()

    sys.exit(app.exec_()) 

This the the gui code:

from PySide import QtCore, QtGui

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(400, 300)
        self.tableView = QtGui.QTableView(Dialog)
        self.tableView.setGeometry(QtCore.QRect(20, 20, 256, 192))
        self.tableView.setObjectName("tableView")

        self.retranslateUi(Dialog)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
2
  • please check if you can find qsqlmysql4.dll in this path C:\Python26\Lib\site-packages\PyQt4\plugins\sqldrivers(if you are using windows). if you can find the dll, the installation is correct. Commented Apr 15, 2013 at 7:21
  • for modern PySide6 the solution in described at stackoverflow.com/a/72169911 Commented Jan 21, 2023 at 22:38

2 Answers 2

1

regarding to PySide, the official 64bit windows installer (downloaded from PySide home page) does support only QSQLITE driver. The 32bit installer support QSQLITE QODBC3 QODBC QPSQL7 QPSQL drivers. R.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! I just decided to use pyqt4 instead of pyside, because the installer has the QMYSQL driver.
I will try to prepare the new PySide release with QMYSQL (and other) driver. I will inform you when it is ready. Regards. R.
@rlacko is there a link to where this was discussed?
0

I decided to use pyqt4 instead of pyside, because the installer contains the QMYSQL driver.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.