How do I export my model from Processing Modeler as .py so that I can edit its code?

This does not seem as intuitive as in previous QGIS versions.


2 Answers 2


Early versions of QGIS 3 did not support exporting models to scripts (See: Why "Export as Python script" button is unaccessible in QGIS 3.0/3.1 Modeler by default?)

From QGIS 3.6, the export to script button is back and creates a proper QGIS3 Processing script:

enter image description here


You can make it accessible.

  1. Find "DlgModeler.ui" and "ModelerDialog.py" files in QGIS folder. (That folder depends on which way you installed it).

    By default (in Windows):
    "DlgModeler.ui" is located in "QGIS_PATH/python/plugins/processing/ui/"
    "ModelerDialog.py" is located in "QGIS_PATH/python/plugins/processing/modeler/"

    additionally you may check this folder "C:/.../QGIS/apps/qgis-ltr/python/plugins/processing"

  2. Open "DlgModeler.ui" in editor (maybe Notepad), find "addaction" tags.
    Add "<addaction name="mActionExportPython"/> and Save.


  3. Open "ModelerDialog.py" in editor and uncomment the lines below and Save it.

    #    QgsApplication.getThemeIcon('/mActionSaveAsPython.svg'))
  4. Open QGIS 3.0



  1. As @ndawson says (in comments), this method just re-adds the removed "Export as Python Script" button. Exported script has QGIS 2.x syntax and it won't be usable in QGIS 3.x. For further information about QGIS 3.x syntax, visit Processing script template for QGIS3.
  2. From v3.6, QGIS supports to export a model as Python script. Look at @underdark's answer.
  • since adding the button I've been getting an error that doesn't seem to be causing issues yet, but thought I'd see if you could see where I might have gone wrong. I'll be posting a follow up question Apr 2, 2018 at 1:06
  • 2
    I didn't realized that the syntax of exported file by "Export as Python script" in QGIS 3.0 (in its current form) is uncompatible with QGIS 3.0, because the way to write Processing script has changed. Further information: Processing script template for QGIS3 Apr 2, 2018 at 2:37
  • 2
    This answer is incorrect - it readds a removed button, but the generated scripts won't actually be usable!
    – ndawson
    Apr 2, 2018 at 19:42
  • I came on just to state that :) there is a related post about why this has been a disabled function. See kadirs comment above. Apr 2, 2018 at 21:06
  • 1
    You're right. I reported this situation to moderators. Sep 22, 2018 at 15:06

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.