Running processing alghorithms works fine from the Python console in QGIS. I am using OSGEO4W (Python 3.7).
However when trying to run the same processing algorithm in PyCharm, I get the following error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:/OSGeo4W64/apps/qgis-ltr/python/plugins\processing\tools\general.py", line 105, in run
return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
File "C:/OSGeo4W64/apps/qgis-ltr/python/plugins\processing\core\Processing.py", line 183, in runAlgorithm
raise QgsProcessingException(msg)
_core.QgsProcessingException: There were errors executing the algorithm.
My preamble looks like the following:
import sys
import os
sys.path.append(r'C:/OSGeo4W64/apps/qgis-ltr/python/plugins')
sys.path.append(r'C:/OSGeo4W64/apps/qgis-ltr/python')
sys.path.append(r'C:/OSGeo4W64/apps/qgis-ltr')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = r'C:/OSGeo4W64/apps/Qt5/plugins'
os.environ['PATH'] += r';C:/OSGeo4W64/apps/qgis-ltr/bin;C:/OSGeo4W64/apps/Qt5/bin'
sys.path.extend([r'C:/OSGeo4W64/apps/qgis-ltr/python',r'C:/OSGeo4W64/apps/Python37/Lib/site-packages'])
from qgis.core import *
from qgis.analysis import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from qgis.utils import *
from PyQt5.QtWidgets import *
import osgeo.gdal
import qgis.utils
QgsApplication.setPrefixPath(r'C:/OSGeo4W64/apps/qgis-ltr', True)
qgs = QgsApplication([], False)
qgs.initQgis()
from processing.core.Processing import Processing
Processing.initialize()
import processing
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
feedback = QgsProcessingFeedback()