I try to run a simple dissolve algorithm in a standalone Python 3 script. My code is following :

from qgis.core import QgsVectorLayer

import processing
from processing.core.Processing import Processing
Processing.initialize()

layer = QgsVectorLayer(layerPath, 'layer 1', 'ogr')

parameters = {'INPUT': layer,
              'OUTPUT': 'memory:'}
dissolved = processing.run('gdal:dissolve', parameters)

But Python tells me : Error: Algorithm not found

But when I print the list of available algorithms :

print('\n'.join(map(str, [alg.id() for alg in QgsApplication.processingRegistry().algorithms()])))

I get the algorithm ID I try to use...

I run my scripts with a batch to include all libraries :

@echo off
set OSGEO4W_ROOT="C:\QGIS 3.0"
call %OSGEO4W_ROOT%\bin\o4w_env.bat
call %OSGEO4W_ROOT%\bin\qt5_env.bat
call %OSGEO4W_ROOT%\bin\py3_env.bat
@echo off
path %OSGEO4W_ROOT%\apps\qgis\bin;%OSGEO4W_ROOT%\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis
set GDAL_FILENAME_IS_UTF8=YES
rem Set VSI cache to be used as buffer, see #6448
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python;%OSGEO4W_ROOT%\apps\qgis\python\plugins;%PYTHONPATH%
rem "%PYTHONHOME%\python" %*
%PYTHONHOME%\python .\main.py %*

Is there something I forgot to import or to do ?

EDIT : after reinstalling QGIS I have another error message :

File "C:\Program Files\QGIS 3.2\apps\qgis\python\plugins\processing\tools\general.py", line 96, in run
    return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
File "C:\Program Files\QGIS 3.2\apps\qgis\python\plugins\processing\core\Processing.py", line 125, in runAlgorithm
    raise QgsProcessingException(msg)
_core.QgsProcessingException: Error: Algorithm gdal:dissolve not found

But processing.algorithmHelp("gdal:dissolve") is working correctly...

Any idea ?

  • Don't you have to start qgis first with QgsApplication.initQgis()? Not sure if this still a thing in qgis 3.0 but it would cause a similar issue in version 2.8 – xlDias Aug 10 at 16:17
  • Please see my comment below. The error comes from QGIS installation. – dmjf08 Aug 10 at 16:21

I complete my message because I found the source of this bug. When I open QGIS 3 I get following error :

Plugin processing. The plugin will be disabled because it crashed qgis during last startup.

Have you ever had this problem ?

  • do this message show everytime you open it? or only if you open it after running the script? the crash mentioned in this error could be the one caused by the script – xlDias Aug 10 at 16:38
  • This is my error now : File "C:\Program Files\QGIS 3.2\apps\qgis\python\plugins\processing\tools\general.py", line 96, in run return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context) File "C:\Program Files\QGIS 3.2\apps\qgis\python\plugins\processing\core\Processing.py", line 125, in runAlgorithm raise QgsProcessingException(msg) _core.QgsProcessingException: Error: Algorithm gdal:dissolve not found – dmjf08 Aug 13 at 15:20
  • can you update your question with the changes you made to get this error? – xlDias Aug 13 at 18:52
  • That's done. Hope someone has a solution. – dmjf08 Aug 14 at 7:58

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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