Using VMTK in Python

Hello,

I’m trying to use the functionality of VMTK in the python interpreter (Slicer stable 20210226, Linux. Slicer-VMTK extension installed from the extension manager). When trying to import vtkvmtk I ge the following error:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/rafael/src/Slicer-stable/build/Slicer-build/NA-MIC/Extensions-29738/SlicerVMTK/lib/Slicer-4.11/qt-loadable-modules/vtkvmtk.py", line 9, in <module>
    from .vtkvmtkCommonPython import *
ImportError: attempted relative import with no known parent package

Is this expected? Is there any other way to make use of VMTK in the Slicer python interpreter?

Thanks in advance!

We import VMTK like this:

It could be nice to fix this and and also the error message at startup (Fail to instantiate module “vtkvmtk” error reported at startup · Issue #22 · vmtk/SlicerExtension-VMTK · GitHub) but we have been holding off changes until VTK9 update and VTK’s new remote module support is in place (see RFC: Toward supporting distribution of VTK based modules on PyPI - Support - VTK).

1 Like

Thank you @lassoan! That solved the problem.

@lassoan Is this a matter of where Slicer-VMTK installs the files, or is Slicer that needs to accommodate the plugin infrastructure?

It is just a matter of where Slicer-VMTK installs VMTK DLLs. For example, the DLLs could be in a subdirectory inside the scripted module folder and not directly in the module folder.