2
$\begingroup$

I'm trying to use specific helper methods from another python file in my Blender addon. Although both my files "__init__.py" and "helpers.py" are located in the same directory, I keep getting a ModuleNotFoundError: No module named 'helpers'.

# __init__.py
import bpy
from helpers import my_register, my_unregister

def register():
    my_register()

def unregister():
    my_unregister()

if __name__ == "__main__":
    register()

I could work around this error by replacing from helpers import ... with from . import helpers, but then I'd have to use a prefix like helpers.my_register(). This gets especially ugly when using decorators:

from bpy.app import handlers
from . import helpers

@helpers.eventhandler(handlers.frame_change_pre)
def on_frame_change_pre(dummy):
    ...

@helpers.eventhandler(handlers.frame_change_post)
def on_frame_change_post(dummy):
    ...

Is it possible to make from {local file} import * work in a Blender addon?

$\endgroup$

1 Answer 1

2
$\begingroup$

You can use from . helpers import FOO to import from a file at the same folder.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .