How to get a plugin path using Python? I tried


I got u'/Applications/QGIS.app/Contents/MacOS/../PlugIns/qgis'

But I actually store the plugin in ~/.qgis2/python/plugins/myplugin

  • 1
    You want the path to your own plugin? – Nathan W Jan 13 '15 at 2:57
  • Yes, I want the path to my own plugin. – wannik Jan 13 '15 at 3:05

I use this in my plugins:

def resolve(name, basepath=None):
    if not basepath:
      basepath = os.path.dirname(os.path.realpath(__file__))
    return os.path.join(basepath, name)

This is handy if you want a file relative to your plugin e.g

  • plugin.py
  • icon.png

resolve('icon.png') will return the full path to icon.png.

Put this function inside a top level file for you plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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