1

I am working with the QGIS code in the QGIS/python/utils.py code (that file path on GitHub).

In line 280 the method append() is used on a dictionary (initialized in line 231), which I believe is not possible.

The line is a part of a method which searches for and updates the list of available plugins.

I am getting an error when I run the method updateAvailablePlugins() (line 270):

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Applications/QGIS.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 283, in updateAvailablePlugins
    plugins.append(pluginName)  # original
AttributeError: 'dict' object has no attribute 'append'

Is this an error in the code? If 'pluginName' should be added to 'plugins' as a dictionary entry, what should the value of the key?

Something to note here is that I am able to use plugins just fine in the QGIS GUI, however I am getting this error when running the code directly in the Python console.

The end goal is to run a plugin, Time Manager, from the Python console, and this appears to be one step in the process.

Here is the github page with the full code: https://github.com/qgis/QGIS/blob/3205c96af629194fa485e072050b677dacfc7f23/python/utils.py

2
  • What do you do to load the plugin? It is important to mimic the way qgis does load its plugins when using the python console. Feb 16, 2018 at 7:44
  • 1
    Ah, and you are wrong. pluigins = {} indeed is a global variable, but in updateAvailablePlugins the name is used as a local variable, because it is assigned to an empty list. See python-course.eu/python3_global_vs_local_variables.php for examples for global vs. local variables. Feb 16, 2018 at 10:03

1 Answer 1

0

If the problem is to load a plugin inside qgis python console, you may check this code:

import qgsAffine # or another plugin modul
plugin = qgsAffine.classFactory(iface) # standard interface for register a plugin in qgis
plugin.initGui() # build the gui of the plugin
plugin.run() # open the plugin (show it's dialog window)

Here i use the plugin qgsAffine to demontrate the interface between QGIS and a plugin. Change it to whatever plugin you need. Of course it must be somewehre in the pythonpath, usually in the users plugin folder.

1
  • Ah, thank you! Your comment above about the global variables was what was very helpful, as somehow the line 'plugins = []' (line 273 in GitHub python/utils.py) was deleted from my local version of the file. This bit of code about loading the plugins is also a nice. Thanks!
    – Rachel W
    Feb 21, 2018 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.