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?
1 Answer 1
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:
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:
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.