I'm writing an addon which has the standard main init.py file and from that file, I'd like to import sets of functions based on the version of Blender currently running the script. These functions would be taken from other .py files in the same directory as init.py.

I've tried importing the functions using:

from .filename import functionname

but when I try to call the functions, Blender reports "name 'bpy' is not defined". I'm also unsure why the . is necessary before the filename but it is.

Am I perhaps going about this the wrong way entirely?

  • $\begingroup$ Just a guess and I don't know if it is required, but is import bpy missing in one of your files? $\endgroup$
    – curious_1
    Nov 29, 2023 at 3:21
  • $\begingroup$ I import bpy in both files but I don't know if that's correct. $\endgroup$
    – gcs_dev
    Nov 29, 2023 at 3:29
  • $\begingroup$ Unfortunately, I can't help. The only times in my limited experience that I've seen that error have been when import bpy was missing. $\endgroup$
    – curious_1
    Nov 29, 2023 at 3:49
  • $\begingroup$ Cool. Thank you for trying! $\endgroup$
    – gcs_dev
    Nov 29, 2023 at 3:55
  • $\begingroup$ The dot means that you're looking at the files in the same directory, .. will look in the parent directory, ... in the grandparent, etc. It's next to impossible to really help you without seeing the script :) $\endgroup$
    – Gorgious
    Nov 29, 2023 at 8:42


You must log in to answer this question.

Browse other questions tagged .