Created
September 4, 2025 12:50
-
-
Save daylanKifky/6951060a476bd7703d5a9a39a0bc009a to your computer and use it in GitHub Desktop.
remove bpy unregister() error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def disable(module_name, *, default_set=False, handle_error=None): | |
| """ | |
| Disables an addon by name. | |
| :arg module_name: The name of the addon and module. | |
| :type module_name: string | |
| :arg default_set: Set the user-preference. | |
| :type default_set: bool | |
| :arg handle_error: Called in the case of an error, taking an exception argument. | |
| :type handle_error: function | |
| """ | |
| import sys | |
| if handle_error is None: | |
| def handle_error(_ex): | |
| import traceback | |
| traceback.print_exc() | |
| mod = sys.modules.get(module_name) | |
| # possible this addon is from a previous session and didn't load a | |
| # module this time. So even if the module is not found, still disable | |
| # the addon in the user prefs. | |
| if mod and getattr(mod, "__addon_enabled__", False) is not False: | |
| mod.__addon_enabled__ = False | |
| mod.__addon_persistent = False | |
| # The problem is some modules `torch` also has a __addon_enabled__ prop | |
| # so they are considered as bpy addon, and tried to disable them issues an error | |
| if not mod.__name__.startswith("torch"): #<<< add this HERE | |
| try: | |
| mod.unregister() | |
| except Exception as ex: | |
| print(mod) | |
| mod_path = getattr(mod, "__file__", module_name) | |
| print("Exception in module unregister():", repr(mod_path)) | |
| del mod_path | |
| handle_error(ex) | |
| else: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment