2

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

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • You should post the section of code where the sqlite driver is loaded. – MalloyDelacroix Dec 04 '17 at 23:40
  • @MalloyDelacroix The problem is not related to the code but to `Pyinstaller`. I actually experiencing the same problem but with `QMYSQL driver` and using `PySide`. The application works fine into a python interpreter but this error appears when running the executable created with `PyInstaller` – Loïc G. Dec 07 '17 at 15:59

1 Answers1

0

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)

Loïc G.
  • 3,087
  • 3
  • 24
  • 36
  • Thanks for the response Loic. I just tried your solution and it seems to work. I also discovered that if I compile pyinstaller in a virtual environment with a fresh install of pyqt5 and python. The drivers are automatically added. Thanks – Godwin Mafireyi Dec 08 '17 at 09:59