# Blender plugin import python from other file fail

I am trying to create a plug-in. In my __Init__.py I am trying to import code from another file operator_add.py, which is located in the same folder in the same level:

if "bpy" in locals():
import importlib
else:


However this does not work, when I install the plug-in it gives me an error saying the No module named operator_add. Did I miss anything?

• Should it be importlib.reload(operator_add)? – batFINGER Jun 7 '18 at 7:11

importlib.reload only reloads modules, not arbitrary objects.

As BatFinger also suggested, import your module (so import operator_add), and not just one name from it (so not from operator_add import OBJECT_add). You can then reload it with importlib.reload(operator_add).

I think whats going on is your system isn't picking up the location of operators_add.py so what I would suggest doing in the operators_add.py and the __init__.py is add this in every add-on script.

import os
import sys
dir = os.path.dirname(bpy.data.filepath)
if not dir in sys.path:
sys.path.append(dir)


This should make it work fine.

edit: Do this then use imp to reload the operators_add.py script

• The addons path is known to blender already eg from io_scene_3ds import import_3ds (the import 3ds addon) there is no need to append any paths. IMO if dir not in sys.path is more readable but not that important. Quite likely needs to be from . import operator_add or from .operator_add import Blah or from addon_module.operator_add import Blah. – batFINGER Jun 8 '18 at 5:40
• Yeah I tried that for my scripts when I was having his issue and it never worked – Skylumz Jun 8 '18 at 7:44
• Every multi-file addon shipped with blender is an example that does work. If you want to run modules from text editor absolute importing from addon_module.submodule import Blah would be the best bet. – batFINGER Jun 8 '18 at 7:54
• I gotta try to get it down weird it doesn't work for me.... maybe I am doing something wrong but Im sure I am doing it as you have said – Skylumz Jun 8 '18 at 10:43