0
$\begingroup$

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
    importlib.reload(OBJECT_add)
else:
    from operator_add import OBJECT_add

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?

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

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).

|improve this answer|||||
$\endgroup$
0
$\begingroup$

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

|improve this answer|||||
$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – batFINGER Jun 8 '18 at 5:40
  • $\begingroup$ Yeah I tried that for my scripts when I was having his issue and it never worked $\endgroup$ – Skylumz Jun 8 '18 at 7:44
  • $\begingroup$ 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. $\endgroup$ – batFINGER Jun 8 '18 at 7:54
  • $\begingroup$ 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 $\endgroup$ – Skylumz Jun 8 '18 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.