I am trying to create a QGIS custom standalone application. I want to add the Google Physical map from OpenLayers plugin to my application when it starts, but I cannot seem to be able to access qgis.utils. These are my imports:

import qgis.core
import qgis.gui
import qgis.utils
import PyQt4.QtCore
import PyQt4.QtGui

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
from qgis.utils import *
import sys
import os

But when I try to print qgis.utils.plugins I get an empty dictionary; {}

In the Python console in QGIS, this code does what I want, I just can't seem to get it working in my custom app;

olplugin = qgis.utils.plugins['openlayers_plugin']
ol_gphyslayertype = olplugin._olLayerTypeRegistry.getById(0)

marked as duplicate by underdark Oct 30 '14 at 19:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


This isn't really possible. Plugins make use of setup which you don't have in your custom application, mainly a iface variable which points to a whole heap of stuff that is normally a QGIS session, e.g mapcanvas, toolbars, actions, composers, etc.

You could in theory create a standalone application that could load plugins but you would have to pretty much rebuild QGIS and that state it normally has in order to run plugins.

Have a look at the code for the OpenLayers plugin you can see how they have done it. You can just take that logic and use it in your application (with credits of course, don't steal code)

  • Thank you, I will look at the code. Had no idea this was near impossible. – Marcus Oct 30 '14 at 5:18
  • Loading plugins to a PyQGIS standalone application has been possible since 2009: geotux.tuxfamily.org/index.php/en/component/k2/item/… (The post is in Spanish) – Germán Carrillo Jan 13 '15 at 3:22
  • Yes its possible but you have to implement a lot of the logic behind the iface object. – Nathan W Jan 13 '15 at 5:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.