Important: Please read the Qt Code of Conduct -

Don't understand why QPSQL plugin isn't working in PySide2 on Windows

  • Hello,
    I am trying to open connection to PostgreSQL databse in a PySide2 application on a Windows 10 machine with no avail.
    At first I encountered the following error:

    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7

    The documentation here: only says about nmake so I had to look for a solution with mingw compiler.
    After hours of searching on the internet on how to build using MinGW compiler, and different solutions with different errors I finally stumbled unto this:
    So I opened the file, followed the comments instructions and the plugin compiled without any issues.
    I copied the plugins(both release and debug) in the plugins/sql directory of Qt installation but the error persisted so I copied the plugins(both release and debug) in the same directory as my application aswell, afterwards, I copied the libpq.dll from the PostgreSQL installation into the application directory.
    After doing all that I still getting the driver error.
    Commands used to build the plugins:

    cd %QTDIR%\5.12.4\Src\qtbase\src\plugins\sqldrivers\psql
    qmake "INCLUDEPATH+=C:/psql/include" "LIBS+=C:/psql/lib/libpq.lib"

    Any ideeas as to why?

  • Lifetime Qt Champion


    Start your application with the QT_DEBUG_PLUGINS environment variable set to 1. It will show you information about what is happening with the loading of the plugins.

  • @SGaist

    Got keys from plugin meta data ("QPSQL7", "QPSQL")
    QFactoryLoader::QFactoryLoader() looking at "C:/Users/Verban Adrian/AppData/Local/Programs/Python/Python37-32/lib/site-packages/PySide2/plugins/sqldrivers/qsqlpsqld.dll"
    Found metadata in lib C:/Users/Verban Adrian/AppData/Local/Programs/Python/Python37-32/lib/site-packages/PySide2/plugins/sqldrivers/qsqlpsqld.dll, metadata=
        "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
        "MetaData": {
            "Keys": [
        "archreq": 1,
        "className": "QPSQLDriverPlugin",
        "debug": true,
        "version": 330752
    "The plugin 'C:/Users/Verban Adrian/AppData/Local/Programs/Python/Python37-32/lib/site-packages/PySide2/plugins/sqldrivers/qsqlpsqld.dll' uses incompatible Qt library. (Cannot mix debug and release libraries.)" 
             not a plugin
    QFactoryLoader::QFactoryLoader() checking directory path "C:/Users/Verban Adrian/AppData/Local/Programs/Python/Python37-32/sqldrivers" ...
    Cannot load library C:\Users\Verban Adrian\AppData\Local\Programs\Python\Python37-32\lib\site-packages\PySide2\plugins\sqldrivers\qsqlpsql.dll: The specified procedure could not be found.
    QLibraryPrivate::loadPlugin failed on "C:/Users/Verban Adrian/AppData/Local/Programs/Python/Python37-32/lib/site-packages/PySide2/plugins/sqldrivers/qsqlpsql.dll" : "Cannot load library C:\\Users\\Verban Adrian\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\PySide2\\plugins\\sqldrivers\\qsqlpsql.dll: The specified procedure could not be found."
    QSqlDatabase: QPSQL driver not loaded
    QSqlDatabase: available drivers: QSQLITE QODBC QODBC3 QPSQL QPSQL7

    It goes for the plugin in PySide2. Guessing I need to build the plugin using that version of PySide2's source code?

  • @SGaist I managed to do a workaround, downloaded PyQt5 and took their plugin for PostgreSQL and it works now....

    Will try today to download Qt5.13 source code(which is the version used in PySide2, from what I could gather), and the build the plugin with that version to see if it works.
    I have installed Qt 5.12.x at the moment, so I am guessing this could be the issue factor.

    I didn't manage to download 5.13, had a lot of other stuff which kept my away from this task, will come back with a replay as soon as I am able.

  • @SGaist

    I couldn't build with Qt 5.13.2

    Cannot read C:/Qt/5.13.2/Src/qtbase/src/plugins/sqldrivers/qtsqldrivers-config.pri: No such file or directory

    But I updated PySide2 to 5.13.2 and it works, so I will be marking this thread as solved.
    Thanks you.

Log in to reply