I am trying to write some scripts to test blender. I have developed some helper tasks that I would like to use from a common module. However when I move the task from the working script into a different file and try and get the script to import from the second file it does not work.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "E:\blender-addons\test\test_import_obj.py", line 14, in <module>
    import test_helper
ModuleNotFoundError: No module named 'test_helper'

So I figured that I needed to at least set the PYTHONPATH to the current directory. However when I do that then the blender bit stops working

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "E:\blender-addons\test\test_import_obj.py", line 214, in <module>
    main(infile, module)
  File "E:\blender-addons\test\test_helper.py", line 22, in copy_plugin
    bpy.ops.wm.addon_install(overwrite=True, filepath=zfile)
NameError: name 'bpy' is not defined

I am using windows to develop my scripts.

What am I missing?

  • $\begingroup$ Please read the docs on blender paths Eg put your test helper module in USER/scripts/modules/ folder and it can be imported with import test_helper $\endgroup$
    – batFINGER
    Commented Aug 2, 2018 at 15:33
  • $\begingroup$ I was hoping to avoid having to copy the files over to the install, they are test files for testing $\endgroup$ Commented Aug 2, 2018 at 15:38
  • $\begingroup$ Please read the docs. The USER path is outside the install path. $\endgroup$
    – batFINGER
    Commented Aug 2, 2018 at 15:40
  • $\begingroup$ @batFINGER So how are multi-file add-ons normally developed? You have to develop inside the scripts/addons folder? $\endgroup$ Commented Aug 2, 2018 at 15:50
  • 1
    $\begingroup$ @RayMairlot on linux for instance I develop addons in my user folder /home/batfinger/.config/blender/2.80/scripts/addons/test_addon/__init__.py I can re-install blender without fear of that user folder being touched. In reality test_addon/ is symbolically linked from elsewhere, but for all extents and purposes is in my user addons folder. Reload addon scripts using F8 shortcut to bpy.ops.script.reload(). Crunch bpy.utils.script_paths('addons') into the python console and it returns a list of locations where blender expects to find addons. $\endgroup$
    – batFINGER
    Commented Aug 2, 2018 at 16:05

1 Answer 1


Don't set PYTHONPATH, but rather add your script's path to sys.path. You can do that manually in Blender's Python Console, in a script you embed in a blend file via Blender's Text Editor, or in a small add-on that you place in a path that's already searched for by Blender.

Non-scripting approaches would be to set an alternative scripts folder in the user preferences, or to use symlinks to make Blender find your code.


You must log in to answer this question.

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