[PyQt] Plugins not loading. Library paths dependent on order of code with QApplication.

Matthew Sorenson veraiste at veraiste.com
Sat Feb 13 00:27:28 GMT 2010


Hi,

The database plugins fail to load for me in certain situations. I 
believe I have narrowed the problem down to the differences between the 
examples at the end. Working with the databases before instantiating a 
QApplication seems to change the library paths. This doesn't appear to 
be the case when using C++ and Qt4.

This could be the correct behavior, but I'm not sure. I discovered it 
trying to load the "Assistant Eric Plugin" in eric4. The plugin works 
for Detlev on various Linux, Win XP, and Win 7.
The PluginAssistantEric.py script has the following check:
         drivers = QSqlDatabase.drivers()
         if drivers.contains("QSQLITE"):
             return True
         else:
             error = self.trUtf8("The SQLite database driver is not 
available.")
             return False

At this point, there are no drivers loaded and it returns false. Placing 
"QtGui.QApplication.addLibraryPath("C:\Python26\Lib\site-packages\PyQt4\plugins")" 
above this snippet will load the drivers. I am using PyQt 4.7 on Python 
2.6.4 and eric 4.4.1.

I'm not sure if this is expected behavior, a configuration error on my 
part, or an error within PyQt. I would appreciate any help.

Thanks,
Matthew Sorenson


Examples:
------------------------------------------------------------------------------------------------------------ 

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit 
(Intel)] on hermes, Standard
 >>> import sys
 >>> from PyQt4 import QtGui, QtSql
 >>> app = QtGui.QApplication(sys.argv)
 >>> QtSql.QSqlDatabase.drivers().count()
7
 >>> db = QtSql.QSqlDatabase.addDatabase("QSQLITE")
 >>> QtGui.QApplication.libraryPaths().count()
2
 >>> print QtGui.QApplication.libraryPaths()[0]
C:/Python26/Lib/site-packages/PyQt4/plugins
 >>> print QtGui.QApplication.libraryPaths()[1]
C:/python26
 >>>
------------------------------------------------------------------------------------------------------------- 

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit 
(Intel)] on hermes, Standard
 >>> import sys
 >>> from PyQt4 import QtGui, QtSql
 >>> QtSql.QSqlDatabase.drivers().count()
0
 >>> app = QtGui.QApplication(sys.argv)
 >>> QtSql.QSqlDatabase.drivers().count()
0
 >>> db = QtSql.QSqlDatabase.addDatabase("QSQLITE")
 >>> StdErr: QSqlDatabase: QSQLITE driver not loaded
QSqlDatabase: available drivers:

 >>> QtGui.QApplication.libraryPaths().count()
1
 >>> print QtGui.QApplication.libraryPaths()[0]
C:/python26
 >>> 
QtGui.QApplication.addLibraryPath("C:\Python26\Lib\site-packages\PyQt4\plugins") 

 >>> QtGui.QApplication.libraryPaths().count()
2
 >>> QtSql.QSqlDatabase.drivers().count()
7
 >>> db = QtSql.QSqlDatabase.addDatabase("QSQLITE")
 >>> StdErr: QSqlDatabasePrivate::removeDatabase: connection 
'qt_sql_default_connection' is still in use, all queries will cease to 
work.
QSqlDatabasePrivate::addDatabase: duplicate connection name 
'qt_sql_default_connection', old connection removed




More information about the PyQt mailing list