Search code examples
pythonubuntuvtk

Setting up VTK, with python3.8 and Ubuntu 20.04


I recently updated my system to Ubunutu 20.04, and my python is now 3.8. Since then all my import vtk lines don't work,

ModuleNotFoundError: No module named 'vtk'

I have tried apt-get python-vtk, pip3 install vtk and pretty much all the standard terminal install commands. Without fail they all are unable to locate the package. I have been searching for ways to sort this out all over the net, but without success.

I am familiar with building Kitware (Cmake and Paraivew) stuff from source so I did so:

git clone https://github.com/Kitware/VTK.git
mkdir VTK/build
cd VTK/build
ccmake .. 
make 
make install

some relevant cmake options are BUILD_SHARED_LIBS=ON, CMAKE_BUILD_TYPE=Release, CMAKE_INSTALL_PREFIX=/usr/local, python3_EXECUTABLE=/usr/bin/python3.8, VTK_WRAP_PYTHON=ON, Python3_INCLUDE_DIR=/usr/include/python3.8, Python3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.8.so, and VTK_PYTHON_OPTIONAL_LINK=ON.

I am able to build it, and I assume I am supposed to turn on python wrapping. Once installed I find I am still unable to get python files to run, still get the same error as mentioned above. I feel like I just need to tell python where to go to get the vtk module, is this correct? If so, where is it and what is its name and how do my make python link to it? Or am I missing something or doing something really stupid?

If there is an apt-get or pip3 install way of doing this that would be preferable, but I think I have exhausted all attempts found by google searching.

Thanks in advance.


Solution

  • Use apt-get install python3-vtk7 (https://packages.ubuntu.com/focal/python3-vtk7) for ubuntu 20.04.

    The python-vtk package is only available for ubuntu 16.04 (https://packages.ubuntu.com/xenial/python-vtk).

    There are no vtk pip wheels for python 3.8, though they do exist for older versions of python. See https://pypi.org/project/vtk/#files