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
  Unexpected termination of program when using JDBC drivers in python with jaydebeapi skarface19 2 253 Feb-17-2024, 12:01 PM
Last Post: skarface19
  Mysql and mysql.connector error lostintime 2 610 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Is Matplotlib.pyplot Loaded DaveG 2 1,275 Apr-06-2022, 06:12 AM
Last Post: DaveG
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,673 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  "ModuleNotFoundError: No module named 'PyQt5.QtWidgets'; 'PyQt5' is not a package" chipx 3 7,240 Dec-09-2021, 07:05 AM
Last Post: chipx
  Package cannot be loaded into PBS queue file emersonpl 1 1,775 Sep-09-2021, 08:06 PM
Last Post: emersonpl
  MacOS BigSur Python3 - dyld: Library not loaded: trillionanswers 1 4,167 Mar-02-2021, 11:00 PM
Last Post: nilamo
  Why is mpl_toolkits loaded? Gribouillis 1 1,564 Jan-30-2021, 08:39 PM
Last Post: Serafim
  start interactive pyhton shell with pre-loaded custom modules Viktor 2 2,140 Apr-09-2020, 08:25 AM
Last Post: Viktor
  external refs by libraries loaded with cdll caldodge 0 1,480 Jul-01-2019, 10:26 PM
Last Post: caldodge

Forum Jump:

User Panel Messages

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