1

My system: Windows 10 Pro 16299, Qt, PyQt 5.11.2, Python 3.6, PostgreSql 10

I tried to use QTableView/QSqlTableModel for in my gui to work with postgresql data. However, I am not able to open the database. I get the error message “Driver not loaded Driver not loaded”.

A new installation of Qt, PostgreSql and PyQt has not solved the problem. I tried also “Dependency Walker” to look for missing dlls, but was not able use the given information.

Do you have an idea how to fix this problem?

As an alternative: Is it possible to use QTableView/QSqlTableModel with psycopg2 (instead of QSqlDatabase)?

Thank you very much in advance!


from PyQt5.QtSql import QSqlDatabase, QSqlQuery, QSqlTableModel  
from PyQt5.QtWidgets import QTableView, QApplication  
import sys

if __name__ == '__main__':

  app = QApplication(sys.argv)  
  db = QSqlDatabase.addDatabase("QPSQL")   
  db.setHostName("localhost")  
  db.setPort(5432)  
  db.setDatabaseName("Test")  
  db.setUserName("postgres")  
  db.setPassword("xxxxx")  
  if (db.open() == False):  
    QMessageBox.critical(None, "Error", db.lastError().text())   
  else:  
    Print("Connected")

Dependency Walker Screenshot

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Joachim W.
  • 25
  • 4

1 Answers1

0

Find the Postgres driver:

C:\Python\Python36\Lib\site-packages\PyQt5\Qt\plugins\sqldrivers\qsqlpsql.dll

where C:\Python\Python36 is your Python installation directory.

Load this file with dependency walker and check whether libpq.dll and all its dependencies can be found.

Typically the two Postgres folders have to be set on the system path:

C:\Program Files\PostgreSQL\10\bin\
C:\Program Files\PostgreSQL\10\lib\

The dll's version incompatibility (64-bit vs 32-bit) may be one of the probable problems.

klin
  • 112,967
  • 15
  • 204
  • 232
  • I added ‪C:\Program Files\PostgreSQL\10\bin\ and C:\Program Files\PostgreSQL\10\lib\ to the path variable. Same error. However, the screenshot from "Dependeny Walker" (please see above) shows that something is missing. How can I fix this? – Joachim W. Jul 04 '18 at 19:25
  • Well, dependencies looks pretty good. I would say *it must run!* Set the new `PATH` in system properties and restart Windows? – klin Jul 04 '18 at 19:53
  • + cleaned up the user properties. Now it is working!! Thanks a lot!! – Joachim W. Jul 04 '18 at 20:39