Python Forum
PyQt5 MySQL Drivers Not Loaded - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: PyQt5 MySQL Drivers Not Loaded (/thread-34494.html)



PyQt5 MySQL Drivers Not Loaded - AdeS - Aug-04-2021

Hi all, I'm' very new to python so please bear with me. I decided to try my hands on PyQt5 to build my GUI everything seemed to be going ok until i tried to connect to MySQL database. I imported all the necessary libraries but keep getting the same error:

QSqlDatabase: QMySQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7

I have searched across the web but can't get a definitive answer. A lot of people have this issue but no one seems to be able to explain the fix without going into some complex explanation.

I'm using MacOS Big Sur, Python 3.9

I will be grateful for any help you can offer


RE: PyQt5 MySQL Drivers Not Loaded - mesbah - Aug-04-2021

Seems needs compiling pyQt5 with mysql driver.


RE: PyQt5 MySQL Drivers Not Loaded - AdeS - Aug-04-2021

(Aug-04-2021, 09:01 PM)mesbah Wrote: Seems needs compiling pyQt5 with mysql driver.

Hi mesbah thanks for your reply. Unfortunately I don’t understand what you mean 😢


RE: PyQt5 MySQL Drivers Not Loaded - mesbah - Aug-04-2021

https://doc.qt.io/qt-5/sql-driver.html#qmysql
and check Para:
How to Build the QMYSQL Plugin on Unix and macOS


RE: PyQt5 MySQL Drivers Not Loaded - AdeS - Aug-04-2021

(Aug-04-2021, 09:24 PM)mesbah Wrote: https://doc.qt.io/qt-5/sql-driver.html#qmysql
and check Para:
How to Build the QMYSQL Plugin on Unix and macOS

Hi mesbah, I went to the page and didn’t understand much of what it was asking me to do. I don’t know what the MySQL header file is, or the libmysqlclient.so. Also I don’t believe I have qmake. I installed PyQt5 and I don’t think it comes with qmake. It seems qmake is only available in Qt which I haven’t installed. Do you know an easier/ less complex way to solve the driver problem? This did not happen with TKinter the MySQL connector worked without any issues. Any help will be appreciated.


RE: PyQt5 MySQL Drivers Not Loaded - AdeS - Aug-05-2021

Hello people it looks like I’m going to give up on this. All the chatter online has gone way over my head. No explanation makes sense to me and I don’t want waste your time. All the experts seem to suggest installing additional things and I don’t want to compromise my laptop. Tried installing QT and I can’t even verify whether the install was successful (should never have moved to Mac - everything is complex and hidden). It seems more like a setup issue which is outside my scope of understanding. Thanks to you all for responses


RE: PyQt5 MySQL Drivers Not Loaded - deanhystad - Aug-05-2021

How about posting your code before you give up. Maybe you are making a little mistake that is easy to fix.


RE: PyQt5 MySQL Drivers Not Loaded - AdeS - Aug-06-2021

(Aug-05-2021, 07:38 PM)deanhystad Wrote: How about posting your code before you give up. Maybe you are making a little mistake that is easy to fix.

Hi i deanhystad - you're right to ask for the snippet. Been banging my head against
a wall and jus got frustrated. see code snippet below (i'm trying to test the connection object):

from PyQt5 import QtSql
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtSql import *

import sys

def search():

    mydb = QtSql.QSqlDatabase.addDatabase("QMySQL")
    mydb.setHostName("localhost")
    mydb.setUserName("root")
    mydb.setPassword("pioneer1")
    mydb.setDatabaseName("FriqueDB")
    mydb.open()

    if mydb.open():

        print('database is opened')
    else: print('database not opened')

btn1 =QPushButton(win)
btn1.setText('Search')
btn1.move(370,210)
btn1.show()
btn1.clicked.connect(search)


win.show()

sys.exit(app.exec_())
This is the output:

Error:
QSqlDatabase: QMySQL driver not loaded QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7