2

I’m trying to develop a custom QGIS 3.42.1 Processing algorithm using the new decorator API (from qgis.processing import alg), but after installation I get no errors and nothing ever shows up in the Toolbox or in the algorithm dialog’s outputs.

What I have QGIS Version: 3.42.1-Münster (Windows)

Script location:

%APPDATA%\QGIS\QGIS3\profiles\default\python\processing\distanceanalysisv1_2\
 ├── __init__.py ← (empty file)
 └── distanceanalysistool.py

Key parts of distanceanalysistool.py:

from qgis.processing import alg
@alg(
 name='distanceanalysistool',
 label='Distance Analysis Tool',
 group='ecologytools',
 group_label='Ecology Tools'
)
@alg.input(type=alg.SOURCE, name='SITE_LAYER', label='Site layer')
@alg.input(type=alg.MULTILAYER, name='NEARBY_LAYERS', label='Nearby layers')
@alg.input(type=alg.DISTANCE, name='MAX_DISTANCE', label='Max distance (m)', defaultValue=1000.0)
@alg.output(type=alg.FILE, name='CSV_OUTPUT', label='CSV output', fileFilter='*.csv', optional=True)
@alg.output(type=alg.VECTOR_LAYER_DEST, name='GPKG_OUTPUT', label='Lines GPKG', fileFilter='*.gpkg', optional=True)
@alg.output(type=alg.VECTOR_LAYER_DEST, name='BUFFER_10_OUTPUT', label='10 km buffer', fileFilter='*.gpkg', optional=True)
@alg.output(type=alg.VECTOR_LAYER_DEST, name='BUFFER_5_OUTPUT', label='5 km buffer', fileFilter='*.gpkg', optional=True)
def distanceanalysistool(instance, parameters, context, feedback, inputs):
 # ... body that writes the four files ...
 return {
 'CSV_OUTPUT': csv_path,
 'GPKG_OUTPUT': gpkg_path,
 'BUFFER_10_OUTPUT': buffer10_path,
 'BUFFER_5_OUTPUT': buffer5_path
 }

What I’ve tried:

Ensured the core Processing plugin is enabled under Plugins → Manage and Install Plugins...

Restarted QGIS several times

Confirmed no errors in View → Panels → Log Messages → Python

Reloaded providers via Processing → Reload Providers

Verified that %APPDATA%\QGIS\QGIS3\profiles\default\python\processing is in the Python provider search paths

The problem No "Python" provider shows up under Settings → Options → Processing → Providers (only GDAL and what3words).

No "Ecology Tools" group in the Processing Toolbox at all.

My question What am I missing in my QGIS configuration or folder structure so that the Python Provider actually loads my @alg‐decorated script and exposes the four output parameters in the GUI?

user2856
73.7k7 gold badges123 silver badges207 bronze badges
asked Jun 9 at 8:59
0

1 Answer 1

2

I think you're getting confused between processing scripts and processing provider plugins.

You have a processing script, not a plugin. You don't need to set up your code as a submodule in a package (i.e. distanceanalysistool.py with __init__.py in a folder called distanceanalysisv1_2).

Just put distanceanalysistool.py in the processing scripts folder:

  • %APPDATA%\QGIS\QGIS3\profiles\default\processing\scripts ✔️

Not

  • %APPDATA%\QGIS\QGIS3\profiles\default\python\processing

That is the default, but you can add other folders as script folders using the Options - Processing - Scripts - Scripts folders setting:

enter image description here

Each @alg decorated function (tool) should be in a separate .py script file in the above scripts folder. You can have one @alg decorated function/tool per script file (though you can have supporting non-@alg decorated functions in the same file).

The scripts provider is always enabled, but you won't see a Scripts toolbox in the Processing toolbox until you have at least one valid processing script .py file in the above folder.

The simple way to get scripts in the right place is to click the Scripts button in the Processing panel and select Add Script to Toolbox:

enter image description here

One common pitfall is that if you have any syntax or other errors when QGIS loads your script (not when actually running), the Scripts toolbox will vanish and you won't be able to access any of your script tools, even the working ones until you fix your script (need to open the file in a text/python editor, not via QGIS) and restart QGIS.

answered Jun 9 at 10:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.