1

I've been forced to try to port to PySide2 from PySide because I'm developing code (on Windows 7) used inside Maya and Maya 2017 has moved to PySide2.

PySide2 ships with Maya but only comes with the driver to talk to sqlite DBs. So I need to tell Qt about a new DIR that contains the MySql driver, like this:

from PySide2 import QtWidgets
QtWidgets.QApplication.addLibraryPath("C:\temp\plugins")

This DIR contains a sub sqldrivers DIR which contains the driver. This works- when I call QtSql.QSqlDatabase.drivers() the new one is there so I've got the right driver and it's being picked up.

However when I create a new DB and call open:

db = QtSql.QSqlDatabase.addDatabase("QMYSQL3")
db.setDatabaseName("my_db")
db.setHostName("host")
db.setUserName("user")
db.setPassword("password")
db.open()

the open command returns False and the DB is not accessible. I call:

db.lastError()

and get:

# Result: <PySide2.QtSql.QSqlError("", "Driver not loaded", "Driver not loaded")  at 0x0000000075410C08> # 

NB: we successfully did the exact same thing with the previous PySide version.

Other threads mention similar things and it turned out to be missing the actual libmysql.dll, which is the actual MySql DLL and can result in the same error if missing. However I definitely have this on my system and it's definitely in the PATH. It's actually the same file that is being successfully picked up through PySide. But the PySide2 driver just wont open a connection to the DB.

I suspect maybe a dodgy driver but wondered if anyone has any experience with this or any advice?

T Melson
  • 11
  • 2

1 Answers1

0

I had the same error, but with postgres. I solved by placing the libpq.dll connector library next to my script.py.

Then for mysql it would be libmysql.dll.

In my case I had to build the libpq.dll from the source of postgres 9.6

It seems that with PySide2 it is not necessary to use: QtWidgets.QApplication.addLibraryPath ("C: \ path_to\ plugins")

using: print (PySide2.QtCore.QLibraryInfo.location (PySide2.QtCore.QLibraryInfo.PluginsPath)), I could see that the path was correct.

a greeting