Littering Your Python Path: The Road to Destruction

December 5, 2012

Well not quite destruction, but a bit of hair pulling…

While working on an update to the Plugin Builder, I encountered a small problem. The Plugin Builder displays the version number in the title bar of its main window. After bumping the version number to 1.8.4 in all the requisite places, it still showed 1.8.3 when testing.

Using grep on all the source files revealed no instance of 1.8.3 in any file.

The title of this post has probably already given you the answer—I had on old version of the plugin in my Python path. The old plugin was getting picked up first when QGIS loaded.

Here’s what happened:

I previously had the old version in my plugin directory (~/.qgis/python/plugins), but moved it up one level so I could test the new one. It turns out this directory is also in the Python path when you load QGIS, a fact that escaped my attention. Using the Python Console in QGIS to display the path revealed the problem. Once I moved the version 1.8.3 plugin out of the way, my new version happily loaded.

The other pitfall you can encounter is if you use the QGIS_PLUGINPATH environment variable during your development. This allows you to specify another directory QGIS will also search for plugins. If you have multiple versions of the same plugin in any of these directories you may be setting yourself up for conflict.

The moral of the story:

Don’t stash old plugins in .qgis/python or you may send yourself down the wrong path…