<div dir="ltr"><div><p style="margin:0px;white-space:pre-wrap">When trying to add a script to the processing toolbox, I get the following error (below) even though iface is imported with "from qgis.utils import iface" in the script. The problem existed with QGIS 3.6 so I upgraded to 3.10 on Windows 10, but it persists, I am using the standalone installer. Any ideas how I can fix this error? </p><p style="margin:0px;white-space:pre-wrap"><br></p><p style="margin:0px;white-space:pre-wrap">Thanks!</p><p style="margin:0px;white-space:pre-wrap">Cliff</p><p style="margin:0px;white-space:pre-wrap"><br></p><p style="margin:0px;white-space:pre-wrap"><span style="font-weight:600;color:rgb(255,0,0)"><br></span></p><p style="margin:0px;white-space:pre-wrap"><span style="font-weight:600;color:rgb(255,0,0)"><br></span></p><p style="margin:0px;white-space:pre-wrap"><span style="font-weight:600;color:rgb(255,0,0)">An error has occurred while executing Python code:</span> <br></p>
<p style="margin:14px 0px 12px;white-space:pre-wrap"><span style="font-size:large;font-weight:600">NameError: name 'iface' is not defined </span></p>
<pre style="margin-top:12px;margin-bottom:12px"><span style="font-family:"Courier New"">Traceback (most recent call last):<br> File "C:/PROGRA~1/QGIS3~1.10/apps/qgis/./python/plugins\processing\script\ScriptAlgorithmProvider.py", line 119, in loadAlgorithms<br> alg = ScriptUtils.loadAlgorithm(moduleName, filePath)<br> File "C:/PROGRA~1/QGIS3~1.10/apps/qgis/./python/plugins\processing\script\ScriptUtils.py", line 66, in loadAlgorithm<br> spec.loader.exec_module(module)<br> File "", line 728, in exec_module<br> File "", line 219, in _call_with_frames_removed<br> File "C:\Users\Cliff\AppData\Roaming\QGIS\QGIS3\profiles\default\processing\scripts\load_json_citywide_api_2.py", line 2, in <br> iface.addVectorLayer(uri, 'Asset Data', 'ogr')<br>NameError: name 'iface' is not defined<br></span></pre>
<p style="margin:0px;white-space:pre-wrap"><br><span style="font-weight:600">Python version:</span> 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] <br><span style="font-weight:600">QGIS version:</span> 3.10.0-A Coruña A Coruña, 6ffa89eb3e <br></p>
<p style="margin:12px 0px;white-space:pre-wrap"><span style="font-size:medium;font-weight:600">Python Path:</span></p>
<ul style="margin:0px"><li style="margin:12px 0px 0px;white-space:pre-wrap">C:/PROGRA~1/QGIS3~1.10/apps/qgis/./python</li>
<li style="margin:0px;white-space:pre-wrap">C:/Users/Cliff/AppData/Roaming/QGIS/QGIS3\profiles\default/python</li>
<li style="margin:0px;white-space:pre-wrap">C:/Users/Cliff/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins</li>
<li style="margin:0px;white-space:pre-wrap">C:/PROGRA~1/QGIS3~1.10/apps/qgis/./python/plugins</li>
<li style="margin:0px;white-space:pre-wrap">C:\Program Files\QGIS 3.10\bin\python37.zip</li>
<li style="margin:0px;white-space:pre-wrap">C:\PROGRA~1\QGIS3~1.10\apps\Python37\DLLs</li>
<li style="margin:0px;white-space:pre-wrap">C:\PROGRA~1\QGIS3~1.10\apps\Python37\lib</li>
<li style="margin:0px;white-space:pre-wrap">C:\Program Files\QGIS 3.10\bin</li>
<li style="margin:0px;white-space:pre-wrap">C:\PROGRA~1\QGIS3~1.10\apps\Python37</li>
<li style="margin:0px;white-space:pre-wrap">C:\PROGRA~1\QGIS3~1.10\apps\Python37\lib\site-packages</li>
<li style="margin:0px;white-space:pre-wrap">C:\PROGRA~1\QGIS3~1.10\apps\Python37\lib\site-packages\win32</li>
<li style="margin:0px;white-space:pre-wrap">C:\PROGRA~1\QGIS3~1.10\apps\Python37\lib\site-packages\win32\lib</li>
<li style="margin:0px;white-space:pre-wrap">C:\PROGRA~1\QGIS3~1.10\apps\Python37\lib\site-packages\Pythonwin</li>
<li style="margin:0px;white-space:pre-wrap">C:/Users/Cliff/AppData/Roaming/QGIS/QGIS3\profiles\default/python</li>
<li style="margin:0px 0px 12px;white-space:pre-wrap">C:\Users\Cliff\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins</li></ul></div><div><br></div></div>