使用 python3.8 和 Ubuntu 20.04 设置 VTK

Setting up VTK, with python3.8 and Ubuntu 20.04

我最近将我的系统更新到 Ubunutu 20.04,我的 python 现在是 3.8。从那以后,我所有的 import vtk 行都不起作用,

ModuleNotFoundError: No module named 'vtk'

我已经尝试了 apt-get python-vtkpip3 install vtk 和几乎所有标准终端安装命令。毫无疑问,他们都无法找到包裹。我一直在网上寻找解决这个问题的方法,但没有成功。

我熟悉从源代码构建 Kitware(Cmake 和 Paraivew)的东西,所以我这样做了:

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

一些相关的 cmake 选项是 BUILD_SHARED_LIBS=ONCMAKE_BUILD_TYPE=ReleaseCMAKE_INSTALL_PREFIX=/usr/localpython3_EXECUTABLE=/usr/bin/python3.8VTK_WRAP_PYTHON=ONPython3_INCLUDE_DIR=/usr/include/python3.8Python3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.8.so,以及 VTK_PYTHON_OPTIONAL_LINK=ON

我能够构建它,我想我应该打开 python wrapping。安装后我发现我仍然无法将 python 文件获取到 运行,仍然会出现与上述相同的错误。我觉得我只需要告诉 python 去哪里获取 vtk 模块,这样对吗?如果是这样,它在哪里,它的名字是什么,我如何对它进行 make python link ?还是我遗漏了什么或做了什么非常愚蠢的事情?

如果有 apt-getpip3 install 的方法更好,但我想我已经用尽了 google 搜索找到的所有尝试。

提前致谢。

对 ubuntu 20.04 使用 apt-get install python3-vtk7 (https://packages.ubuntu.com/focal/python3-vtk7)。

python-vtk 包仅适用于 ubuntu 16.04 (https://packages.ubuntu.com/xenial/python-vtk)。

python 3.8 没有 vtk pip 轮子,尽管 python 的旧版本确实存在。参见 https://pypi.org/project/vtk/#files

我遇到了与您相同的问题:我从 Kitware 构建了 VTK,但后来在 python 中导入 vtk 时出错。我固定在 $PYTHONPATH 中添加 vtk,你应该在 VTK/build/lib 下找到它。现在对我来说一切正常!

编辑:我还发现在 Kitware 网站上可以使用 python3.8 的轮子,然后: pip3 install https://www.vtk.org/files/release/9.0/vtk-9.0.0-cp38-cp38-linux_x86_64.whl 应该也可以