Setting up VTK, with python3.8 and Ubuntu 20.04

喜你入骨 提交于 2020-12-26 04:02:05

问题


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.


回答1:


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




回答2:


I was having your same problem: I have built VTK from Kitware but then I got error importing vtk in python. I fixed adding vtk in $PYTHONPATH, you should find it under VTK/build/lib . Everything works fine for me now!

EDIT: I found also that on the Kitware site the wheels for python3.8 are available, then: pip3 install https://www.vtk.org/files/release/9.0/vtk-9.0.0-cp38-cp38-linux_x86_64.whl should work as well



来源:https://stackoverflow.com/questions/61754702/setting-up-vtk-with-python3-8-and-ubuntu-20-04

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!