Search code examples
pyqt5pyinstallerqsqldatabase

pyinstaller QSqlDatabase: QSQLITE driver not loaded QSqlDatabase: available drivers:


I have witten a GUI app using pyqt5 and includes a QtSql database QSQLITE. The app works perfectly. However when I run pyinstaller to a package my app, the app runs until the time where it has to invoke QtSQL DATABASE QSQLITE. This is the error I get

QSqlDatabase: QSQLITE driver not loaded QSqlDatabase: available drivers:

How do I load the driver so that it can be included when I run pyinstaller.

Thank you


Solution

  • I experienced the same problem with QMYSQL driver using PySide and I found a solution.

    You need to manually include the driver into the qt4_plugins/sqldrivers/ bundle directory.
    For that, in your spec file add :

    a = Analysis(...
        binaries=[('/usr/lib/x86_64-linux-gnu/qt4/plugins/sqldrivers/libqsqlmysql.so', 'qt4_plugins/sqldrivers')],
        ...
    )
    

    This will works for QMYSQL driver but you just need to find the name of the SQLITE driver (probably libqsqlsqlite)