0

I'm new to python and attempting to split off my executes for my panels buttons into a new .py file. However, when I try to run the script I receive the following error :

init.py line 27 in "ImportError: attempted relative import with no known parent package"

the related init.py lines are :

if "bpy" in locals():
    import importlib
    importlib.reload(xmlhandler)
    importlib.reload(zokfunctions)
else:
    from bl_wep_export import xmlhandler 
    from bl_wep_export import zokfunctions
if "bpy" in locals():
import importlib
importlib.reload(xmlhandler)
importlib.reload(zokfunctions)

else: from bl_wep_export import xmlhandler from bl_wep_export import zokfunctions

import bpy

from math import radians from .zokfunctions import execute

The zokfunctions.py file has a simple

def execute(self, context):
print("TEST")
return {'FINISHED'}

I've tried several solutions, like removing the period before zokfunctions or using a class in zokfunctions called Hello and registering it, which throws an attribute error if I remember correctly..

I do my editing in VScode and the files itself are in my blender addons folder installed as an addon, so it is addons/myaddon/the init file and zokfunctions file.

File Structure

terkles
  • 1
  • 1

1 Answers1

0

To the future me if I make more addons and to newer programmers when it comes to blender, the issue isn't actually the scripts at all. Blenders in-house text editor cannot edit multi file addons, if you try it will throw this error. I was going insane trying to figure out what was wrong with my addon and comparing it to other code.

To conclude, if you're making a multi file addon, it'll work if the syntax is right and it's installed, and you can still edit it this way..

terkles
  • 1
  • 1
  • It's not that text editor cannot edit multi-file addons, more so that relative imports may not work if from __main__ thread. Related https://blender.stackexchange.com/questions/183773/trying-to-make-a-menu-using-multiple-modules/183817#183817 or in your case from myaddon.zokfunctions import execute will work both as an addon or from the text editor. – batFINGER May 20 '21 at 14:20