[PyQt] PyQt5 5.7: QPSQL not loaded

Sibylle Koczian nulla.epistola at web.de
Sun Nov 13 16:42:12 GMT 2016


Hello,

I can't get the QPSQL driver to work any more.

Versions of everything: OS is Windows 10, Python 3.5.2, PostgreSQL 
9.6.1, PyQt 5.7 installed from PyPi, all of it 64 bit.

This has worked before. I suspect the recent PostgreSQL upgrade from 9.5 
to 9.6, is that possible? Or the change from PyQt5 5.6 (Windows binaries 
from the Riverbank website) to 5.7 (wheels from PyPi)? The database 
driver dlls are present in the ...\Qt\plugins\sqldrivers of my PyQt5 
installation. Moreover I can connect to MSSql using ODBC and to MariaDB.

Script to show the problem and compare with Sqlite:

------------------------------------------------------------

#!/usr/bin/env python

import sys
from PyQt5 import QtCore
from PyQt5 import QtSql

def checkQPSQL():
     result = QtSql.QSqlDatabase.isDriverAvailable('QPSQL')
     print("PostgreSQL-Treiber verfügbar? {}".format(result))
     db = QtSql.QSqlDatabase.addDatabase("QPSQL", "postgresql")
     cname = db.connectionName()
     print("db.connectionName() = ", cname)
     print("db.lastError:", db.lastError().text())
     db.setDatabaseName("sib")
     db.setHostName("localhost")
     db.setUserName("sib")
     db.setPassword("immergut")
     result = db.open()
     print("Datenbank geöffnet? {}".format(result))
     db.close()
     if result:
         if db.isOpen():
             print("Datenbank konnte nicht geschlossen werden.")
             print(db.lastError().text())
         else:
             print("Datenbank geschlossen.")
     QtSql.QSqlDatabase.removeDatabase(cname)

def checkQSQLITE():
     result = QtSql.QSqlDatabase.isDriverAvailable('QSQLITE')
     print("Sqlite-Treiber verfügbar? {}".format(result))
     db = QtSql.QSqlDatabase.addDatabase("QSQLITE", "sqlite")
     cname = db.connectionName()
     print("db.connectionName() = ", cname)
     print("db.lastError:", db.lastError().text())
     result = db.open()
     print("Datenbank geöffnet? {}".format(result))
     db.close()
     if result:
         if db.isOpen():
             print("Datenbank konnte nicht geschlossen werden.")
             print("db.lastError:", db.lastError().text())
         else:
             print("Datenbank geschlossen.")
     QtSql.QSqlDatabase.removeDatabase(cname)

if __name__ == "__main__":
     app = QtCore.QCoreApplication(sys.argv[1:])

     dbliste = QtSql.QSqlDatabase.drivers()
     print(dbliste)
     print("-----")
     checkQPSQL()
     print("-----")
     checkQSQLITE()

------------------------------------------------------------------------

Output (copied from command window):

['QSQLITE', 'QMYSQL', 'QMYSQL3', 'QODBC', 'QODBC3', 'QPSQL', 'QPSQL7']
-----
PostgreSQL-Treiber verfügbar? True
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 
QPSQL QPSQL7
db.connectionName() =  postgresql
db.lastError: Driver not loaded Driver not loaded
Datenbank geöffnet? False
QSqlDatabasePrivate::removeDatabase: connection 'postgresql' is still in 
use, all queries will cease to work.
-----
Sqlite-Treiber verfügbar? True
db.connectionName() =  sqlite
db.lastError:
Datenbank geöffnet? True
QSqlDatabasePrivate::removeDatabase: connection 'sqlite' is still in 
use, all queries will cease to work.
--------------------------------------------------------------------------

Additional question: if I start this script from an IDE (IDLE or Wing) 
the error messages starting with "QsqlDatabase:", "QSqlDatabasePrivate:" 
don't appear. What's that?

Thank you for any sort of help,
Sibylle


More information about the PyQt mailing list