0

I can't access the SQL related drivers in PyQt5. I need said drivers to do everything.

I installed PyQt5 with Anaconda

I started with code to create the connection, check that the connection works, create an app for the connection

con = QSqlDatabase.addDatabase("QSQLITE")
con.setDatabaseName("solar_system_objects.sqlite")

# Create the application
app = QApplication(sys.argv)

# Try to open the connection, and handle possible errors
if not con.open():
    QMessageBox.critical(
        None,
        "App Name - Error!",
        "Database Error: %s" % con.lastError().databaseText(),
    )
    sys.exit(1)

# Create the application's window
win = QLabel("Connection Successfully Opened!")
win.setWindowTitle("App Name")
win.resize(200, 100)
win.show()
sys.exit(app.exec_())

which gave me the error Database Error: Driver not loaded

Based on what I googled, I tried to check the avaialbe drivers with

print(list(map(str, QSqlDatabase.drivers()))) which returns an empty list [], not the expected list with a half dozen or so drivers that is expected to come with PyQt5

I have no clue what went wrong here. Is it possible that I have the drivers by PyQt5 isn't seeing them? Or is it possible that I need to get the drivers, especially QSQLITE, somewhere, and if so where and how?

0 Answers0