# Using VMTK in Python

**URL:** <https://discourse.slicer.org/t/using-vmtk-in-python/16479>\
**Category:** VMTK\
**Tags:** python, vmtk\
**Created:** [March 11, 2021, 2:37pm UTC](https://discourse.slicer.org/t/using-vmtk-in-python/16479 "2021-03-11T14:37:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RafaelPalomar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafaelpalomar/32/1436_2.png) [@RafaelPalomar](https://discourse.slicer.org/u/RafaelPalomar)\
**Post date:** [March 11, 2021, 2:37pm UTC](https://discourse.slicer.org/t/using-vmtk-in-python/16479/1 "2021-03-11T14:37:25Z")

</div>

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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 11, 2021, 2:48pm UTC](https://discourse.slicer.org/t/using-vmtk-in-python/16479/2 "2021-03-11T14:48:01Z")

</div>

We import VMTK like this:

> <https://github.com/vmtk/SlicerExtension-VMTK/blob/3787ea4a300da28ec5f0824f0715f2713b631155/ExtractCenterline/ExtractCenterline.py#L503>

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](https://github.com/vmtk/SlicerExtension-VMTK/issues/22)) 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](https://discourse.vtk.org/t/rfc-toward-supporting-distribution-of-vtk-based-modules-on-pypi/4873)).

---

<div class="post-metadata">

**Author:** ![RafaelPalomar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafaelpalomar/32/1436_2.png) [@RafaelPalomar](https://discourse.slicer.org/u/RafaelPalomar)\
**Post date:** [March 11, 2021, 4:21pm UTC](https://discourse.slicer.org/t/using-vmtk-in-python/16479/3 "2021-03-11T16:21:14Z")

</div>

Thank you @lassoan! That solved the problem.

---

<div class="post-metadata">

**Author:** ![RafaelPalomar](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rafaelpalomar/32/1436_2.png) [@RafaelPalomar](https://discourse.slicer.org/u/RafaelPalomar)\
**Post date:** [March 12, 2021, 9:03am UTC](https://discourse.slicer.org/t/using-vmtk-in-python/16479/4 "2021-03-12T09:03:09Z")

</div>

> [@lassoan](#):
>
> 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](https://github.com/vmtk/SlicerExtension-VMTK/issues/22))

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 27, 2021, 6:36pm UTC](https://discourse.slicer.org/t/using-vmtk-in-python/16479/5 "2021-03-27T18:36:53Z")

</div>

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.
