Skip to content

Commit 6a4b973

Browse files
ENH: Enable relative import of Slicer Python-wrapped libraries
Improve the fallback mechanism in `slicer/__init__.py` to support relative import of Slicer Python-wrapped libraries (kits) when they are distributed as standalone Python packages (e.g., `slicer-mrml`). This change allows importing modules using relative paths when absolute imports fail, supporting package layouts like: ``` slicer_mrml/ ├── __init__.py ├── vtkAddon/ ├── vtkSegmentationCore.so └── qMRMLWidgetsPythonQt/ ``` This makes it possible to use Slicer Python kits in isolated package distributions outside the monolithic Slicer application structure.
1 parent d6c7975 commit 6a4b973

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Base/Python/slicer/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ def _createModule(name, globals, docstring):
194194
try:
195195
exec("from %s import *" % (kit))
196196
except ImportError as detail:
197-
print(detail)
197+
# Try kit relative import if installed in as a traditional package
198+
try:
199+
exec("from .%s import *" % (kit))
200+
except ImportError:
201+
print(detail)
198202

199203
del kit
200204

0 commit comments

Comments
 (0)