2

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 ?

asked Aug 9, 2018 at 12:55
2
  • 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 Commented Aug 10, 2018 at 16:17
  • Please see my comment below. The error comes from QGIS installation. Commented Aug 10, 2018 at 16:21

1 Answer 1

1

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 ?

answered Aug 10, 2018 at 15:49
4
  • 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 Commented Aug 10, 2018 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 Commented Aug 13, 2018 at 15:20
  • can you update your question with the changes you made to get this error? Commented Aug 13, 2018 at 18:52
  • That's done. Hope someone has a solution. Commented Aug 14, 2018 at 7:58

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.