I've been trying to get standalone QGIS python scripting to work, but for some reason after I import processing, I cannot print anything to the console, nor can I write anything to file. My end goal is to create a library of standalone processing scripts, so being able to output information to the console is important to me.
I slightly altered the code from Error: algorithm not found, since the solution given gave me the error of "no module named processing".
My code is as follows:
#!/usr/bin/python print "1" import qgis print "2" from qgis.core import * print "3" from qgis.utils import * utils.uninstallErrorHook() print "4" app = qgis.core.QgsApplication(, True) print "5" import processing print "6" class DummyInterface(object): def __init__(self): self.destCrs = None def __getattr__(self, *args, **kwargs): def dummy(*args, **kwargs): return DummyInterface() return dummy def __iter__(self): return self def next(self): raise StopIteration def layers(self): # simulate iface.legendInterface().layers() return qgis.core.QgsMapLayerRegistry.instance().mapLayers().values() iface = DummyInterface() plugin = processing.classFactory(iface) f = open("/home/alex/output.txt", "a") a_list = processing.alglist() for item in a_list: f.write(str(item)) f.write(len(a_list)) f.close()
When run from the terminal, this is what I get:
alex@blackbook-bear: ~ $ python test.py 1 2 3 4 5 alex@blackbook-bear: ~ $ cat /home/alex/output.txt cat: /home/alex/output.txt: No such file or directory alex@blackbook-bear: ~ $
import processingis raising an exception, but something is hiding the stderr output.