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

Phil Thompson phil at riverbankcomputing.com
Sat Feb 13 10:04:45 GMT 2010


On Fri, 12 Feb 2010 18:27:28 -0600, Matthew Sorenson
<veraiste at veraiste.com>
wrote:
> 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

Assuming you are using the GPL binary installer, the path to the plugins
directory isn't correct until the qt.conf file has been processed. This
happens during the QCoreApplication ctor call.

You might expect that it would also be done in QSqlDatabase.drivers() (as
it might be influenced by the contents of the plugins directory) but that
doesn't seem to be the case.

Phil

> 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
> 
> 
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt


More information about the PyQt mailing list