MacOS 下安装编译VTK教程,亲测有效,MacOS + VTK + CMaker + Python
具体安装和贬义步骤如下:1. 下载VTK 对应MacOS的源码 : https://vtk.org/download/#latest
下载CMake并进行安装,https://cmake.org/
下载Python并进行安装,https://www.python.org/
2. 安装完成后,输入 cmake 和 python 能够调用命令。如果出现找不到,需要手动添加下环境变量:
export CMAKE_ROOT=/Applications/CMake.app/Contents/bin/ #你的安装地址
export PATH=$CMAKE_ROOT;PATH #设置到PATH路径下
3. 在下载的VTK目录下创建build文件夹,并进行配置
cd Downloads/VTK/
mkdir build
cd build/
4. 配置
ccmake ..
在弹出的配置中,点击 c 进行配置,确保一下环境变量是 ON
BUILD_SHARED_LIBS
PYTHON_WRAPPING
点击 g 进行生成
5. 开始编译
输入: make
6.时间比较长,编译完后设置相关环境变量进行测试
export LD_LIBRARY_PATH=/Users/plmhome/Downloads/VTK/build/bin/
export DYLD_FALLBACK_LIBRARY_PATH=/Users/plmhome/Downloads/VTK/build/bin/
export PYTHONPATH=/Users/plmhome/Downloads/VTK/build/bin/
export PYTHONPATH=$PYTHONPATH:/Users/plmhome/Downloads/VTK/Wrapping/Python/
sudo make install
7. 输入vtkpython 然后import vtk 可以看到导入了包
8. 为了方便,直接将上述变量加入到 profile中
sudo/etc/profile
vi后 插入上述环境设置,这里注意如果要配置VSCode,vtkmodules生成在 usr/local/lib 下
9. 大功告成!通过创建一个例子,直接运行,可以看到结果如下
If you receive this error:
ImportError: No module named vtk
add the following line to ~/.bashrc
export PYTHONPATH=/home/doriad/bin/VTK/lib:/home/doriad/bin/VTK/lib/site-packages:/home/doriad/bin/VTK/Wrapping/Python:$PYTHONPATH
Try to run the script again. If you get something like this:
ImportError: libvtkCommonPythonD.so.pv3.7: cannot open shared object file: No such file or directory
Add the following to ~/.bashrc
export LD_LIBRARY_PATH=/home/doriad/bin/VTK/lib:$LD_LIBRARY_PATH
页:
[1]