[GIS] NameError when running script QGIS Python 3

pyqgispythonqgis

I'm trying to run a script that loops through a series of point layers and interpolates using the TIN interpollation method using python on QGIS. The script worked in the past, but now it fails with the following error:

NameError: name 'QgsProcessingFeedback' is not defined

import qgis.analysis
import qgis.core
import processing
import os
import fnmatch
from qgis.core import QgsProcessingFeedback #added based on [post 194737][1]

use_cols = [6,9,10,11]
col_names = ["Depth","Velocity","Froude","Stress"]
source_geopackage = "D:/GIS/TRF2/PC3_hydropts.gpkg"
interim_path = "D:/GIS/TRF2/Raster_output/"
export_path = "D:/GIS/TRF2/PC3_rasters/"
layers = qgis.utils.iface.mapCanvas().layers() #using canvas layers
for layer in layers:
layerType = layer.type()
if layerType == QgsMapLayer.VectorLayer:
    for i in range(0,len(use_cols)):
        col = use_cols[i]
        output_file_name = layer.name()+"_"+col_names[i]
        export_file_name = interim_path + output_file_name+".tif"
        vlayer = source_geopackage+"|layername="+layer.name()+"::~::0::~::"+str(col)+"::~::0"
        processing.run("qgis:tininterpolation", {
        'INTERPOLATION_DATA':vlayer,
        'METHOD':0,'COLUMNS':2487,'ROWS':929,
        'EXTENT':'1793310.0,1801470.0,498942.0,501991.0 [EPSG:2285]',
        'OUTPUT': export_file_name})

Traceback (most recent call last):
File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\code.py", line 91, in runcode
exec(code, self.locals)
File "", line 13, in
File "C:/PROGRA~1/QGIS3~1.0/apps/qgis/./python/plugins\processing\tools\general.py", line 84, in run
return Processing.runAlgorithm(algOrName, parameters, onFinish, feedback, context)
File "C:/PROGRA~1/QGIS3~1.0/apps/qgis/./python/plugins\processing\core\Processing.py", line 119, in runAlgorithm
feedback = QgsProcessingFeedback()
NameError: name 'QgsProcessingFeedback' is not defined

I'm running QGIS v3.0.2 on Windows, and accessing Python through the QGIS console.

When I wrote the loop, I ran TIN interpolation through the processing framework and copied the settings from the history. I tried to repeat that process, but I get the same error. The algorithm runs fine through processing.

Best Answer

Add feedback = QgsProcessingFeedback() as a parameter for processing.run():

feedback = QgsProcessingFeedback() # I'd put this out of any for loops

processing.run("qgis:tininterpolation", {
        'INTERPOLATION_DATA':vlayer,
        'METHOD':0,'COLUMNS':2487,'ROWS':929,
        'EXTENT':'1793310.0,1801470.0,498942.0,501991.0 [EPSG:2285]',
        'OUTPUT': export_file_name
    },
    feedback=feedback)
Related Question