13

Hi everyone I'm in some way new with PyQGIS and I've been trying to run a script in QGIS 3.0 without success (it prefectly ran in 2.18) and always get the same error:

AttributeError: module 'processing' has no attribute 'runalg' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\code.py", line 91, in runcode exec(code, self.locals) File "", line 8, in TypeError: catching classes that do not inherit from BaseException is not allowed

Does this has something to do with PYTHONPATH? I can't even see the list of algorithms when typing: processing.alglist()

2 Answers 2

14

This is not an answer to the original question, but to a follow-up question in a comment ("Also how can I see the list and options of algorithms?").

In QGIS 3, the processing algorithms can be listed in the QGIS Python console (Python 3) using (see https://gis.stackexchange.com/a/274902/22646 and https://gis.stackexchange.com/a/274874/22646):

QgsApplication.processingRegistry().algorithms()

To list the names (IDs):

for alg in QgsApplication.processingRegistry().algorithms(): print(alg.id())

Getting help for an algorithm (including input parameters and output):

processing.algorithmHelp("qgis:union")

There is also:

processing.algs.help.shortHelp.keys()
print("\n".join(processing.algs.help.shortHelp.keys()))

But it does not seem to include algorithms from for instance gdal and grass.

2
  • The QGIS documentation has now been updated (see docs.qgis.org/testing/en/docs/user_manual/processing/…). Commented Jun 28, 2018 at 23:27
  • Great answer, @Håvard Tveite . I am having trouble running an external PyQGIS script though, since it cannot find the processing algorithm I'm trying to run: processing.run("qgis:rastersampling", params) I can run any ("native") processing algorithm easily by adding QgsNativeAlgorithms() via the following line: QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) But I'm not sure how to add a similar line to add any of the "qgis" processing algorithms. Any ideas?
    – grego
    Commented Jul 30, 2020 at 18:28
14

In QGIS 3, use processing.run.

For instance:

QGIS 2.x processing.runalg('gdalogr:convertformat', ...

QGIS 3.0 processing.run('gdal:convertformat', ...

1
  • It works perfectly fine. Also how can I see the list and options of algorithms? I've tried processing.alglist() and processing.list() but both throw a similar error. Commented Mar 14, 2018 at 17:28

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.