How to correctly enable Cycles from add-on? My add-on requires Cycles to be enabled as I append some classes to existing Cycles types at registration.
I made a function to check if Cycles is enabled:
def cycles_check():
    import addon_utils
    is_enabled,is_loaded = addon_utils.check('cycles')
    if not is_loaded:
        print ('Cycles is required to use Photographer, enabling the add-on automatically.')
        success = addon_utils.enable('cycles')
        if success:
            print ('Cycles is now enabled.')
            return True
    else:
        return True

It &quot;seems&quot; to work: if Cycles is disabled when I enable my add-on, it enables it and my add-on can register properly. I can see Cycles in the render engine lists.
Cycles is required to use Photographer, enabling the add-on.
module changed on disk: 'C:\\Blender\\daily\\blender-2.92.0-6fb7d0f55927-windows64\\2.92\\scripts\\addons\\cycles\\__init__.py' reloading...
Cycles is now enabled.

But... Cycles is actually not properly enabled. The add-on in the preferences is not checked, and the Cycles Device property is missing, which breaks the UI but also crashes Blender if I start a render.

Traceback (most recent call last):
  File &quot;c:\Blender\daily\blender-2.92.0-6fb7d0f55927-windows64\2.92\scripts\modules\bpy_types.py&quot;, line 808, in draw_ls
    func(self, context)
  File &quot;c:\Blender\daily\blender-2.92.0-6fb7d0f55927-windows64\2.92\scripts\addons\cycles\ui.py&quot;, line 2217, in draw_device
    col.active = show_device_active(context)
  File &quot;c:\Blender\daily\blender-2.92.0-6fb7d0f55927-windows64\2.92\scripts\addons\cycles\ui.py&quot;, line 114, in show_device_active
    return context.preferences.addons[__package__].preferences.has_active_device()
I found a solution looking at how bpy.ops.preferences.addon_enable(module=&quot;cycles&quot;) was using addon_utils.enable, it needed default_set=True as an argument, which forced the add-on to be checked in the preferences and fixed the errors.
def cycles_check():
    import addon_utils
    is_enabled,is_loaded = addon_utils.check('cycles')
    if not is_loaded:
        print ('Cycles is required to use Photographer, enabling the add-on automatically.')
        success = addon_utils.enable('cycles', default_set=True)
        if success:
            print ('Cycles is now enabled.')
            return True
    else:
        return True