1

I try to write a PyQGIS python script to work standalone in the python IDE without GUI, out of QGIS interface following the oficial tutorial.

The tutorial for pyqgis in standalone scripts says:

    from qgis.core import *

    # supply path to qgis install location
    QgsApplication.setPrefixPath("/usr", True)#for linux

    # create a reference to the QgsApplication, setting the
    # second argument to False disables the GUI
    qgs = QgsApplication([], False)

    # load providers
    qgs.initQgis()

    # Write your code here to load some layers, use processing algorithms, etc.

    # When your script is complete, call exitQgis() to remove the provider and
    # layer registries from memory
    qgs.exitQgis()

If I write print 'hello world' it shows that message succesfully

from qgis.core import *
# supply path to qgis install location
QgsApplication.setPrefixPath("/usr", True)#for linux

# create a reference to the QgsApplication, setting the
# second argument to False disables the GUI
qgs = QgsApplication([], False)
print 'hello world'
# load providers
qgs.initQgis()

# Write your code here to load some layers, use processing algorithms, etc.

# When your script is complete, call exitQgis() to remove the provider and
# layer registries from memory
qgs.exitQgis()

The tutorial says # Write your code here to load some layers, use processing algorithms, etc. after the line qgs.initQgis() and before qgs.exitQgis().

But if i add lines for processing plugins like :

qgs.initQgis()
sys.path.append('/usr/share/qgis/python/plugins')
from processing.core.Processing import Processing
import processing
Processing.initialize()
processing.alghelp("saga:slopeaspectcurvature")
qgs.exitQgis()

These commands don't work, they don't show me anything.

If i write that command lines in other places in the script it dont show me anything, not even my hello world.

If i write sys.path in the beginning of the script it doesn't show me anything again.

Do you have any idea how to write the right code to get access to the processing tools with standalone pyhon script?

On the python console inside the QGIS import processing and processing.alghelp("saga:slopeaspectcurvature") work fine.

Your Answer

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

Browse other questions tagged or ask your own question.