Some of the external QGIS plugins contain processing algorithms integrated by the processing toolbox after installation, e.g. the plugin "Shape Tools".
How can the processing algorithms from external plugins be run from PyQGIS standalone scripts?
import sys
from qgis.core import QgsApplication, QgsVectorLayer, QgsProcessingFeedback, QgsProcessingRegistry
# Supply path to qgis install location
QgsApplication.setPrefixPath("C:/Program Files/QGIS3.34.4/apps/qgis-ltr", True)
# Create a reference to the QgsApplication. Setting the
# second argument to False disables the GUI.
qgs = QgsApplication([], False)
# Load providers
qgs.initQgis()
import processing
from processing.core.Processing import Processing
Processing.initialize()
# Add the user profile plugins path
sys.path.append("C:/Users/<user>/AppData/Roaming/QGIS/QGIS3/profiles/default/python/plugins")
# Import the shapetools provider
try:
from shapetools.provider import ShapeToolsProvider
except ImportError:
print("ShapeToolsProvider not found in shapetools")
# Add the processing algorithms
#QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
#Initialize the shapetools
QgsApplication.processingRegistry().addProvider(ShapeToolsProvider())
running in cmd gets the error:
Traceback (most recent call last): File "C:\gis\scripts\test_prod_standalone.py", line 63, in <module>
buffer_shape_tools = processing.run("shapetools:createcircle", File "C:\Program Files\QGIS
3.34.4\apps\qgis-ltr\python\plugins\processing\tools\general.py", line 109, in run
return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context) File "C:\Program Files\QGIS
3.34.4\apps\qgis-ltr\python\plugins\processing\core\Processing.py", line 158, in runAlgorithm
raise QgsProcessingException(msg)
_core.QgsProcessingException: Error: Algorithm shapetools:createcircle not found
It seems the shapetools algorithm is not initialized. Git plugin repo see: Git repo shapetools plugin