How can I get a list of the installed addons and the version number so I can print out and use as a simple reference when checking for updated scripts? I've looked at bpy.types.Addons
and bpy.types.UserPreferences.addons
but getting a list of the addon names is eluding me. Any help would be appreciated.
-
$\begingroup$ Can you explain what you are using this for? (it can give us insights into weakness in the API if you are forced to use an undocumented are). $\endgroup$– ideasman42Sep 10, 2013 at 22:19
1 Answer
Blender has a module it uses for addon management called addon_utils
, this isn't in the API docs and is only for internal usage. But its a fairly straightforward module.
This script prints all addon versions or (-1, -1, -1) if there is no version.
import addon_utils
for mod in addon_utils.modules():
print(mod.bl_info.get('version', (-1, -1, -1)))
Note, that the modules may be fake, that is to say, a module object that only contains bl_info
, this is done to avoid importing the module just to display it in the preferences (before its enabled).
Other functions of interest are...
addon_utils.enable(module_name, default_set=True, persistent=False, handle_error=None)
addon_utils.disable(module_name, default_set=True, handle_error=None)
# (reloads from disk)
addon_utils.modules_refresh(module_cache=addons_fake_modules)
# returns all modules
addon_utils.modules(module_cache=addons_fake_modules, refresh=True)
Suggest reading addon_utils.py
, if you need more info.
Note, if you just want to access enabled addons, this is a lot more simple...
what about:
import bpy
print(bpy.context.user_preferences.addons.keys())
that returns something like:
['io_scene_3ds', 'io_scene_fbx', 'io_anim_bvh', 'io_mesh_ply', 'io_scene_obj', 'io_scene_x3d',
'io_mesh_stl', 'io_mesh_uv_layout', 'io_curve_svg', 'cycles', 'sire_o', 'space_view3d_move_orig
in']
So to get the modules you can do...
import bpy
import sys
context = bpy.context
for mod_name in context.user_preferences.addons.keys():
mod = sys.modules[mod_name]
print(mod.bl_info.get('version', (-1, -1, -1)))
@zeffii noted this in his answer which has since been deleted so including here.
-
$\begingroup$ Thank you for pointing out the addon_utils module. I'll try this out $\endgroup$ Sep 10, 2013 at 19:17
-
$\begingroup$ This worked great (although I'm sure this comes as no surprise to you!) $\endgroup$ Sep 10, 2013 at 21:55
-
$\begingroup$ I have compiled Blender as a Python3 module so I don't have access to the GUI. I am installing an addon and enable it using the bpy module. I then save the user preferences using
bpy.ops.wm.save_userpref()
and exit Python.Next time that I doimport bpy
I don't see the addon API being added to the bpy module.Do you know how I can fix that?If I run the same exact script in Blender terminal (when using the GUI) everything works fine.(You may answer here) $\endgroup$– AmirSep 17, 2018 at 19:51