I can't seem to add a picture to my composition using PyQGIS in Windows 8. My code is based on the example I found in this question. I've tried using .setPicturePath and .setPictureFile but none seem to work for me. Instead, my map shows a red 'x' where the arrow should appear. Since the question was answered 2 years ago, has this method been superseded?

My code is:

#Add north arrow
arrow = QgsComposerPicture(c) 
arrow.setPicturePath("C:\Program Files\QGIS 2.18\apps\qgis\svg\arrows\Arrow_03")
arrow.setSceneRect(QRectF(0,0,10,10)) #Resize 

Ideally, I want to replace the path with QgsApplication.svgPaths()[0] + "\Arrow_03"but I figured I should get it working with a hard coded path first

  • 3
    you are missing the file extension
    – JGH
    Commented Sep 12, 2017 at 12:12

2 Answers 2


Along with JGH comment the path to the image needs to be forward slashes or have the 'r' in front of it so the back slashes are not interpreted as character escapes.


arrow.setPicturePath(r"C:\Program Files\QGIS 2.18\apps\qgis\svg\arrows\Arrow_03.svg")


arrow.setPicturePath("C:/Program Files/QGIS 2.18/apps/qgis/svg/arrows/Arrow_03.svg")

You are missing the file extension

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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