0
$\begingroup$

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

$\endgroup$

1 Answer 1

0
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ It's not that text editor cannot edit multi-file addons, more so that relative imports may not work if from __main__ thread. Related blender.stackexchange.com/questions/183773/… or in your case from myaddon.zokfunctions import execute will work both as an addon or from the text editor. $\endgroup$
    – batFINGER
    May 20, 2021 at 14:20

You must log in to answer this question.

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