using vtk 8.2.0 with python wrappings with anaconda

(Abhishek Venkataram) #1

Hi,

i built vtk with python wrappings successfully, when i go to bin in the build folder and run the vtkpython executable, it works properly with anaconda python version that i have given.

when i open a new terminal window and try run python and try to import vtk, i get no module found error.

if i try to install it in the anaconda/lib/python3.6/site-packages and then run i get
Fatal Python error: PyThreadState_Get: no current thread error.

how do i connect built vtk to anaconda python?

thanks

vtk build issue with QT and python wrapping
(Dan Lipsa) #2

You’ll have to rebuild VTK and

at configure time, make sure the python executable and python headers point to conda versions rather than system versions.

So look in your CMakeCache.txt for all python variables and make sure the point correctly.

Hope it helps,

Dan

(Abhishek Venkataram) #3

Hi Dan,

i used cmake GUI, i did set all the python variables to anaconda version, the lib, include and exec paths,
after build, it is created a python folder in lib in the build folder with path build/lib/python3.6/site-packages/ with vtk inside it. and the bin folder in build path has vtkpython exec.


(i used release build)

when i copied contents of build/lib/python3.6/site-packages/ to anaconda/lib/python3.6/site-packages/ it is throwing the Fatal Python error: PyThreadState_Get: no current thread error.

(Dan Lipsa) #4

Abhishek,
You may need to build VTK master to fix this problem and you’ll have to patch VTK master like this:


diff --git a/Utilities/Python/CMakeLists.txt b/Utilities/Python/CMakeLists.txt
index 632069bc0d..44e4371b1a 100644
--- a/Utilities/Python/CMakeLists.txt
+++ b/Utilities/Python/CMakeLists.txt
@@ -147,7 +147,7 @@ cmake_dependent_option(VTK_PYTHON_OPTIONAL_LINK
   # `target_link_options`.
   # XXX(Linux): Currently, this causes missing symbols on Linux in ParaView.
   # More investigation is necessary.
-  "FALSE;BUILD_SHARED_LIBS;COMMAND target_link_options" OFF)
+  "BUILD_SHARED_LIBS;COMMAND target_link_options" OFF)
 
 add_library(PythonUsed INTERFACE)
 add_library(VTK::PythonUsed ALIAS PythonUsed)

See the following thread for context:

https://discourse.vtk.org/t/segfault-for-python-importing-vtk-but-not-for-vtkpython/126

(Dan Lipsa) #5

Also, you’ll need cmake >= 3.13 for this to work

vtk build issue in windows os
(Dan Lipsa) #6

The patch won’t be needed after this MR goes in.
https://gitlab.kitware.com/vtk/vtk/merge_requests/5611

(Abhishek Venkataram) #7

Hi Dan, i tested this solution and it worked

thanks for your help in resolving this solution