Class already registered as subclass (module structure for addon) I am working on creating an addon and I have a main __init__.py file and then I have a another file we will call utils.py. __init__ registers all the classes in utils by import utils and then bpy.utils.register_class(utils.CLASS), it has several classes and that file registers them all.

If you run the file once it works fine, but if you run it again it gives the error that the class is already registered as a subclass.

utils contains a bpy.types.Panel and bpy.types.Operator class. It is almost like the bpy.utils.unregister_class(utils.CLASS) isn't working. File
You can replace all calls to bpy.utils.register_class(...) by a single call to

bpy.utils.register_module(__name__)


and all calls to bpy.utils.unregister_class(...) by a single

bpy.utils.unregister_module(__name__)


You won't have to (un-)register single classes ever again and your error should no longer occur. Do it in __init__.py only and import all module files from here (from . import ...).

Note that the order of class definitions may matter, e.g. if you use a custom property group class in an operator (the code of the property group class needs to be above the class definition of the operator).

Example addon to show the file structure and imports: blender-addon.zip