The post introduces how to create an environment for learning VTK by Python.

The basic conditions on my computer:
VTK-8.1.1
macOS Mojave 10.14
Python 2.7.10

Write a bash script and run it.

cmake ./ -G "Unix Makefiles" \
-DVTK_USE_QVTK:BOOL=ON \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DVTK_USE_GUISUPPORT:BOOL=ON \
-DVTK_QT_VERSION=5 \
-DModule_vtkGUISupportQt:BOOL=ON \
-DModule_vtkGUISupportQtOpenGL:BOOL=ON \
-DModule_vtkGUISupportQtSQL:BOOL=ON \
-DModule_vtkGUISupportQtWebkit:BOOL=OFF \
-DModule_vtkRenderingQt:BOOL=ON \
-DModule_vtkViewsQt:BOOL=ON \
-DVTK_WRAP_TCL:BOOL=ON \
-DTK_INTERNAL_PATH:PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/tk-private \
-DVTK_WRAP_PYTHON:BOOL=ON \
-DVTK_PYTHON_VERSION=2.7.10 \
-DPYTHON_EXECUTABLE=/usr/bin/python \
-DPYTHON_INCLUDE_DIR=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/python2.7

The last four options are related to Python. The variable PYTHON_INCLUDE_DIR represents a path that contains C/C++ files.
Then we make and sudo make install.
Finally, we can see the similar information.

...
-- Installing: /usr/local/lib/python2.7/site-packages/vtk/vtkImagingMorphologicalPython.so
...
-- Installing: /usr/local/lib/python2.7/site-packages/vtk/vtkViewsInfovisPython.so
-- Installing: /usr/local/bin/vtkpython

Now we can try to run a python script by command vtkpython, but you may can see the error information, ImportError: No module named vtkCommonCorePython.
We need to set the environment variable PYTHONPPATH for finding python library files.

export PYTHONPATH="/usr/local/lib/python2.7/site-packages":"/usr/local/lib/p ython2.7/site-packages/vtk"

Run it again, you may can see the error information, python Library not loaded: @rpath/QtWidgets.framework/Versions/5/QtWidgets. We have to set the variable DYLD_FRAMEWORK_PATH to find Qt lib files.

export DYLD_FRAMEWORK_PATH=$DYLD_FRAMEWORK_PATH:/Users/weiyang/Qt5.9.2/5.9.2 /clang_64/lib

Let’s write the two commands into the file ~/.bashrc, then run source ~/.bashrc.
Finally, we can run a python script for VTK.

Here is a simple python script for drawing cone in VTK, VTK – A Simple Example Written In Python Script, we can run it by vtkpython.

Categories: VTK

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
0
Would love your thoughts, please comment.x
()
x