QSqlDatabase: QPSQL driver not loaded

Rich Shepard rshepard at appl-ecosys.com
Thu May 20 18:18:46 BST 2021


Running PyQt5-5.13.2 on Slackware64-14.2 with Postgresql-12.2 and
Python3-3.7.2. Also installed are /usr/lib/qt/include/QtSql/QPSQLDriver,
/usr/lib/qt/include/QtSql/QPSQLResult,
/usr/lib64/qt/include/QtSql/QPSQLDriver, and 
/usr/lib64/qt/include/QtSql/QPSQLResult.

Developing my first PyQt5/SQL database application and working on a simple
module (to add a new activity type to the database table) I get these
errors:

$ python activitytype.py 
QSqlDatabase: QPSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE

The database connection code is:
 	# Set up database connection
         self.db = qts.QSqlDatabase.addDatabase('QPSQL')
         self.db.setDatabaseName('bustrac')
         if not self.db.open():
             error = self.db.lastError().text()
             qtw.QMessageBox.critical(
                 None, 'DB Connection Error',
                 'Could not open database file: '
                 f'{error}')
             sys.exit(1)

The build scripts for Qt5 and python3-PyQt4 have no configuration option for
database drivers.

The web page <https://doc.qt.io/qtforpython/overviews/sql-driver.html>
describes building on Windows, not linux.

1. How do I learn what SQL drivers are installed (other than QSQLITE)?

2. How do I make the QPSQLDriver available for use?

TIA,

Rich



More information about the PyQt mailing list