Python Forum
PyQt5 MySQL Drivers Not Loaded
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyQt5 MySQL Drivers Not Loaded
#1
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
Reply
#2
Seems needs compiling pyQt5 with mysql driver.
Reply
#3
(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 😢
Reply
#4
https://doc.qt.io/qt-5/sql-driver.html#qmysql
and check Para:
How to Build the QMYSQL Plugin on Unix and macOS
Reply
#5
(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.
Reply
#6
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
Reply
#7
How about posting your code before you give up. Maybe you are making a little mistake that is easy to fix.
AdeS likes this post
Reply
#8
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Package cannot be loaded into PBS queue file emersonpl 1 357 Sep-09-2021, 08:06 PM
Last Post: emersonpl
  MacOS BigSur Python3 - dyld: Library not loaded: trillionanswers 1 2,525 Mar-02-2021, 11:00 PM
Last Post: nilamo
  Why is mpl_toolkits loaded? Gribouillis 1 596 Jan-30-2021, 08:39 PM
Last Post: Serafim
  start interactive pyhton shell with pre-loaded custom modules Viktor 2 960 Apr-09-2020, 08:25 AM
Last Post: Viktor
  external refs by libraries loaded with cdll caldodge 0 766 Jul-01-2019, 10:26 PM
Last Post: caldodge
  When are imports loaded? MuntyScruntfundle 2 1,344 Feb-10-2019, 03:47 PM
Last Post: ichabod801
  python to install printer drivers automatic leoxucn 4 5,059 Jul-10-2017, 09:21 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020