I am working on my first add-on, though I am pretty experienced with Python having written multiple apps using Django. My project structure looks like this:
lib/
application/
blender/
models/
operators/
test_local_simulation_operator.py
...
ui/
panels/
test_simulation_panel.py
...
domain/
...
__init__.py
...
My init file contains the following code after the bl_info
.
from bpy.utils import register_classes_factory
from lib.blender.operators.test_local_simulation_operator import (
TestLocalSimulationOperator,
)
from lib.blender.ui.panels.test_simulation_panel import TestSimulationPanel
classes = (TestLocalSimulationOperator, TestSimulationPanel)
register, unregister = register_classes_factory(classes)
I am using VS Code on Windows with the Blender Development extension. When I launch the add-on using the Blender: Start
command, I get the following import error:
Traceback (most recent call last):
File "c:\Users\[user]\Blender Foundation\Blender 2.91\2.91\scripts\modules\addon_utils.py", line 351, in enable
mod = __import__(module_name)
File "C:\Users\[user]\AppData\Roaming\Blender Foundation\Blender\2.91\scripts\addons\[project_folder]\__init__.py", line 22, in <module>
from lib.blender.operators.test_local_simulation_operator import (
ModuleNotFoundError: No module named 'lib.blender'
I have tried adding an init file to all of my sub-modules to no avail. The only way I can get it to work is by adding this import style to each init file chained throughout my project.
# lib/__init__.py
from . import blender, ...
This seems like a lot of unnecessary overhead not required in conventional Python projects, so my conclusion is that I am doing something wrong here.
What should I do to get my modules to import properly?
from . import
though. You can always check how the default addons do things. $\endgroup$