I have recently got in touch with vmtk but I have still some issues making it work from python scripts. I would like to used it to implement an automatic segmentation and meshing workflow.
I have set up an Ubuntu 20.04 Dockerimage and build vmtk following the instructions on the
http://www.vmtk.org/download/ page to install the development version.
It is possible to run simple commands from the terminal like “vmtk vmtkimagereader -ifile ct_scan.nii.” If I want to execute the
myscript.pyexample after running chmod u+x myscript.py i get the following traceback:
File "./myscript.py", line 4, in <module> from vmtk import vmtkscripts
File "/build/vmtk/vmtk-build/Install/lib/python3.9/site-packages/vmtk/vmtkscripts.py", line 158, in <module> exec('from '+item+' import *')
File "<string>", line 1, in <module> File "/build/vmtk/vmtk-build/Install/lib/python3.9/site-packages/vmtk/vmtkactivetubes.py", line 19, in <module> import vtk File "/build/vmtk/vmtk-build/Install/lib/python3.9/site-packages/vtk.py", line 31, in <module> all_m = importlib.import_module('vtkmodules.all')
File "/root/miniconda3/envs/vmtk/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/build/vmtk/vmtk-build/Install/lib/python3.9/site-packages/vtkmodules/all.py", line 7, in <module>
from .vtkCommonCore import *
ModuleNotFoundError: No module named 'vtkmodules.vtkCommonCore'
I would really appreciate some hints on how to get that working.
Thank you very much,
Might be that your script is getting executed by a different python installation? I can’t think of a scenario where the command line pype scripts can find vtk, but the python script version can’t.
Thank you very much for your thoughts and the quick reply.
I had a similar idea earlier and was playing around with different python versions 3.9 or even python2.7 (which should both be supported by vmtk) and got the same error but I think that you are referring to a vmtk python version, right?
Should I set the python version to something like:
/build/vmtk/vmtk-build/Install/lib/python3.9/ or what are you suggesting?
I was wondering if there are multiple python installations (e.g. default system python and one you have installed), because if “vmtk vmtkimagereader -ifile ct_scan.nii.” from the terminal works I would be very confused about it not being able to find vtk.
vmtkimagereader definitely needs vtk.
I haven’t exactly tried python 2.7, but I’m pretty sure the current vmtk master branch is not going to be compatible with python 2.7. The instructions at
http://www.vmtk.org/download were written about three years ago and aren’t necessarily accurate at this point, although the builds scripts are reasonably up to date.
How exactly are you building vmtk (superbuild?) and which versions of VTK and ITK are you using?
Yes, in fact there are two versions 2.7 and 3.9.5 but the default during build and execution is 3.9 which comes from anaconda and not the system itself as i just figured out.
I am strictly following the build instructions form the download page:
cmake .. \
The versions are: itk 5.2 and vtk9.1
Are here any issues that are not obvious to me?
If not I would try to build it again ensuring that I use the system’s python as 3.9.
If you’re already using anaconda, you could install it from the conda-forge channel with
conda config --add channels conda-forge
conda install vmtk
Do you actually need it to be built from source?
Yes and no,
I have tried to use an anaconda installation as you suggested above first but the
conda install vmtk had some issues when using the python API that are already fixed when building from the current master.
Since I want to embed vmtk in a larger python-workflow in a dockerimage I was hoping to circumvent those issues by building it directly but this turns out to be trickier than expected xD
The conda-forge version is up to date with the current master branch. You can try installing specifically the new version with
conda install vmtk=1.5 .
Otherwise you can have a look at the cmake setup for Slicer’s builds which incorporate vmtk (https://github.com/vmtk/SlicerExtension-VMTK/blob/master/SuperBuild/External_VMTK.cmake) or the anaconda packaging builds (https://github.com/vmtk/vmtk/blob/master/distribution/build.sh), presumably something has gone wrong during the cmake configuration