I'm trying to run the following python script:

from qgis.core import *
import sys
import os
import qgis.utils
from qgis.analysis import *

app = QgsApplication([],True,"")

# supply path to where is your qgis installed
QgsApplication.setPrefixPath("/Applications/QGIS.app/Contents/MacOS/", True)

# load providers

import processing

layer3 = QgsVectorLayer("../output/precinctsZipcodes.shp", "intersect", "ogr")
if layer3.isValid():
    print "Loaded layer 3"
    print "Layer 3 failed to load!"

processing.runalg("qgis:exportaddgeometrycolumns", layer3, 0, "../output/precinctsZipcodesArea.shp")


However, the line processing.runalg("qgis:exportaddgeometrycolumns", layer3, 0, "../output/precinctsZipcodesArea.shp") isn't saving any output. The strange thing is that this syntax works when I run it directly in the python console. Does anybody know what might be happening?

  • 1
    Along with what @gcarrillo has mentioned with changing paths and such, try replacing processing.runalg with general.runalg.
    – Joseph
    Nov 6, 2015 at 10:46
  • 1
    You're right Joseph, general.runalg() is the way I call QGIS processing algorithms from standalone scripts, as you can also see in my answer. Nov 6, 2015 at 17:17

1 Answer 1


Not sure of what could be happening there, but the next code snippet has worked for me on my GNU/Linux machine:

# Prepare the environment
import sys
from qgis.core import *
from PyQt4.QtGui import *
app = QApplication([])
QgsApplication.setPrefixPath("/usr", True)

# Prepare processing framework 
from processing.core.Processing import Processing
from processing.tools import *

# Run the algorithm
layerInput = QgsVectorLayer('world_adm0.shp', 'test', 'ogr')
general.runalg("qgis:exportaddgeometrycolumns", layerInput, 0, "tmp.shp")

# Exit applications

I successfully got the tmp.shp file saved in the folder from which I run the script. Could you give it a try? Just adjust QGIS prefix and other paths to reflect your system configuration.

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.