[Qgis-user] NameError: name 'iface' is not defined when importing script to processing toolbox

Cliff Patterson cpatterson at psdrcs.com
Mon Nov 25 13:10:50 PST 2019


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?


Thanks!

Cliff




An error has occurred while executing Python code:

NameError: name 'iface' is not defined

Traceback (most recent call last):
  File "C:/PROGRA~1/QGIS3~1.10/apps/qgis/./python/plugins\processing\script\ScriptAlgorithmProvider.py",
line 119, in loadAlgorithms
    alg = ScriptUtils.loadAlgorithm(moduleName, filePath)
  File "C:/PROGRA~1/QGIS3~1.10/apps/qgis/./python/plugins\processing\script\ScriptUtils.py",
line 66, in loadAlgorithm
    spec.loader.exec_module(module)
  File "", line 728, in exec_module
  File "", line 219, in _call_with_frames_removed
  File "C:\Users\Cliff\AppData\Roaming\QGIS\QGIS3\profiles\default\processing\scripts\load_json_citywide_api_2.py",
line 2, in
    iface.addVectorLayer(uri, 'Asset Data', 'ogr')
NameError: name 'iface' is not defined


Python version: 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC
v.1914 64 bit (AMD64)]
QGIS version: 3.10.0-A Coruña A Coruña, 6ffa89eb3e

Python Path:

   - C:/PROGRA~1/QGIS3~1.10/apps/qgis/./python
   - C:/Users/Cliff/AppData/Roaming/QGIS/QGIS3\profiles\default/python
   -
   C:/Users/Cliff/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins
   - C:/PROGRA~1/QGIS3~1.10/apps/qgis/./python/plugins
   - C:\Program Files\QGIS 3.10\bin\python37.zip
   - C:\PROGRA~1\QGIS3~1.10\apps\Python37\DLLs
   - C:\PROGRA~1\QGIS3~1.10\apps\Python37\lib
   - C:\Program Files\QGIS 3.10\bin
   - C:\PROGRA~1\QGIS3~1.10\apps\Python37
   - C:\PROGRA~1\QGIS3~1.10\apps\Python37\lib\site-packages
   - C:\PROGRA~1\QGIS3~1.10\apps\Python37\lib\site-packages\win32
   - C:\PROGRA~1\QGIS3~1.10\apps\Python37\lib\site-packages\win32\lib
   - C:\PROGRA~1\QGIS3~1.10\apps\Python37\lib\site-packages\Pythonwin
   - C:/Users/Cliff/AppData/Roaming/QGIS/QGIS3\profiles\default/python
   -
   C:\Users\Cliff\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20191125/d5d671a9/attachment.html>


More information about the Qgis-user mailing list