Organize your folder structure like this:
myaddon/
├── __init__.py
├── operators/
├── first_operator.py
In the __init__.py do this:
import bpy
from .operators.first_operator import FirstOperator
bl_info = {
"name": "MyAddon",
"description": "A demo addon",
"author": "myname",
"version": (1, 0, 0),
"blender": (2, 7, 9),
"wiki_url": "my github url here",
"tracker_url": "my github url here/issues",
"category": "Animation"
}
def register():
bpy.utils.register_module(__name__)
def unregister():
bpy.utils.unregister_module(__name__)
In the operators/first_operator.py file, do this:
import bpy
class FirstOperator(bpy.types.Operator):
bl_label = "First Operator"
bl_idname = "myaddon.first_operator"
bl_description = "A demo operator"
def execute(self, context):
print("hello world")
return {"FINISHED"}
You'll have to install the addon to use it. You can't just run the __init__.py from the text editor in Blender to make it work.
myaddonname is where you can import using absolute imports. – J. Bakker Apr 09 '18 at 12:37