I got an error trying to read the “version” of addons = addon.bl_info.get(“version”) does not work.
What is wrong?
I got an error trying to read the “version” of addons = addon.bl_info.get(“version”) does not work.
What is wrong?
I like a guessing game as much as the next guy, but you’ll get an answer faster if you tell us what the error is.
shame on me, sorry:
Python: Traceback (most recent call last):
File “\script.py”, line 8, in
File “\script.py”, line 8, in
AttributeError: ‘Addon’ object has no attribute ‘bl_info’
import addon_utils
for module in addon_utils.modules():
if module.__name__ == addon.module:
print(module.bl_info.get('version', (-1, -1, -1)))
import bpy
import addon_utils
import csv
for module in addon_utils.modules():
if module.__name__ == addon.module:
print(module.bl_info.get('version', (-1, -1, -1)))
# Write aCSV file
#with open('addon_info.csv', 'w', newline='') as file:
# writer = csv.writer(file)
# writer.writerow(["Addon Name", "Version"])
# for info in addon_info:
# writer.writerow(info)
Python: Traceback (most recent call last):
File "\script.py", line 9, in <module>
NameError: name 'addon' is not defined
addon.module
isn’t a thing, i’m guessing that was supposed to be placeholder code for whatever your addon’s module name is called… you haven’t shared that info with us so we have no way of knowing what it is. honestly at this point I’m not even sure you’re using an addon, based on your errors it looks like you’re just trying to run a loose script (which isn’t an addon, and therefore doesn’t have a version to ‘get’). Is this your complete code? An addon has a bl_info dictionary defined in the ini.py, where ‘version’ is defined. If you don’t have a bl_info you don’t have an addon.
Actually what I want is quite simple. I would like to have an overview of all installed addons in Blender including the path and version number. Sorted in the alphabetical order to compare whether there are updates. I don’t want to do more.
You should look into 3.6\scripts\startup\bl_ui\space_userpref.py
, in particular, the draw call for the USERPREF_PT_addons
class.
here’s a simplified version of the look up (showing just the enabled addons):
import bpy, addon_utils
prefs = bpy.context.preferences
used_ext = {ext.module for ext in prefs.addons}
addons = [
(mod, addon_utils.module_bl_info(mod))
for mod in addon_utils.modules(refresh=False)
]
for mod, info in addons:
modname = mod.__name__
if modname in used_ext:
version = info['version'] if info['version'] else "(0.0.0)"
print(modname, version)
Thank you! This is helpful, but I think I can do it with Python and OS directly.