Importing QGIS Processing in stand-alone python script?
Linux QGIS 2.18.1
With this code a got it, run Processing from standalone script:
#!/usr/bin/env python
import qgis
from qgis.core import *
import sys
app = QgsApplication([],True, None)
app.setPrefixPath("/usr", True)
app.initQgis()
sys.path.append('/usr/share/qgis/python/plugins')
from processing.core.Processing import Processing
Processing.initialize()
from processing.tools import *
print Processing.getAlgorithm("qgis:creategrid")
So i managed to get it working, thanks @Joseph for your hints:
# Import required modules
# Python modules
import sys
import time
import datetime
import os
from getpass import getuser
# Qgis modules and environment
from qgis.core import *
import qgis.utils
from PyQt4.QtCore import QFileInfo, QSettings
from PyQt4.QtGui import QApplication
app = QApplication([])
QgsApplication.setPrefixPath("/usr", True)
QgsApplication.initQgis()
# Prepare processing framework
sys.path.append('/home/' + getuser() + '/.qgis2/python/plugins')
from processing.core.Processing import Processing
Processing.initialize()
And I coud test it with
print Processing.getAlgorithm("qgis:creategrid")
My issue, I guess, comes from the fact that I imported the modules at the beginning of my script and then tried create the Qgi obkects from within a function. I guess it would be possible to do so as well but there is probably a flaw in my Python skills.
Now I'll try to actually ust the processing module :-)