<div dir="ltr"><div>Hi Normanius,</div><div><br></div><div>You will have to turn off the following C++ VTK modules, since they use the Python C API but don't have the Python version number as part of their library name:</div><div>  FiltersPython</div><div>  MPI4Py</div><div>  RenderingMatplotlib</div><div><br></div><div>This should get you a bit further along.</div><div><br></div><div> - David</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 11, 2018 at 3:17 PM, normanius <span dir="ltr"><<a href="mailto:juch@zhaw.ch" target="_blank">juch@zhaw.ch</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear all

I build VTK 8.1.0 from source with python support enabled. Everything works fine as long as I build and install either for python 2.7 or python 3.5 separately. Here is the build instructions I use for building VTK on Mac: 

<pre>VTK_INSTALL_DIR="/opt/dev/<wbr>versions/vtk/vtk-8.1.0-qt5-<wbr>shared"
mkdir build-python3.5
cd build-python3.5
cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release \
                  -DVTK_WRAP_PYTHON=ON \
                  -DBUILD_EXAMPLES=OFF \
                  -DBUILD_SHARED_LIBS=ON \
                  -DBUILD_TESTING=OFF \
                  -DCMAKE_INSTALL_PREFIX="$VTK_<wbr>INSTALL_DIR" \
                  -DCMAKE_MACOSX_RPATH=ON \
                  -DCMAKE_INSTALL_RPATH="$VTK_<wbr>INSTALL_DIR/lib" \
                  -DVTK_PYTHON_VERSION=3 \
                  -DPYTHON_EXECUTABLE="/Library/<wbr>Frameworks/Python.framework/<wbr>Versions/3.5/bin/python3" \
                  -DPYTHON_INCLUDE_DIR="/<wbr>Library/Frameworks/Python.<wbr>framework/Versions/3.5/<wbr>include/python3.5m/" \
                  -DPYTHON_LIBRARY="/Library/<wbr>Frameworks/Python.framework/<wbr>Versions/3.5/lib/libpython3.5.<wbr>dylib" \
                  -DVTK_Group_Qt=ON \
                  -DVTK_QT_VERSION=5 \
                  -DCMAKE_PREFIX_PATH="$QT_DIR/.<wbr>."
ninja
ninja install
</pre>

<pre>mkdir build-python2.7
cd build-python2.7
# Same installation target!
VTK_INSTALL_DIR="/opt/dev/<wbr>versions/vtk/vtk-8.1.0-qt5-<wbr>shared"
cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release \
                  -DVTK_WRAP_PYTHON=ON \
                  -DBUILD_EXAMPLES=OFF \
                  -DBUILD_SHARED_LIBS=ON \
                  -DBUILD_TESTING=OFF \
                  -DCMAKE_INSTALL_PREFIX="$VTK_<wbr>INSTALL_DIR" \
                  -DCMAKE_MACOSX_RPATH=ON \
                  -DCMAKE_INSTALL_RPATH="$VTK_<wbr>INSTALL_DIR/lib" \
                  -DVTK_PYTHON_VERSION=2 \
                  -DPYTHON_EXECUTABLE="/Library/<wbr>Frameworks/Python.framework/<wbr>Versions/2.7/bin/python2" \
                  -DPYTHON_INCLUDE_DIR="/<wbr>Library/Frameworks/Python.<wbr>framework/Versions/2.7/<wbr>include/python2.7/" \
                  -DPYTHON_LIBRARY="/Library/<wbr>Frameworks/Python.framework/<wbr>Versions/2.7/lib/libpython2.7.<wbr>dylib" \
                  -DVTK_Group_Qt=ON \
                  -DVTK_QT_VERSION=5 \
                  -DCMAKE_PREFIX_PATH="$QT_DIR/.<wbr>."</pre>


If I use different installation targets <pre>VTK_INSTALL_DIR_PY2</pre> and <pre>VTK_INSTALL_DIR_PY3</pre>, I can import vtk at the following locations without any problems:
<pre>cd $VTK_INSTALL_DIR_PY2/lib/<wbr>python2.7/site-packages; python -c "import vtk"  # No error
cd $VTK_INSTALL_DIR_PY3/lib/<wbr>python3.5/site-packages; python -c "import vtk"  # No error
</pre>
However if I set VTK_INSTALL_DIR_PY2 equal to $VTK_INSTALL_DIR_PY3, I will get an error for the version that was installed second. 

I cannot follow why this problem occurs at all, because the installed wrapper binaries (for instance libvtkRenderingCorePython27D-<wbr>8.1.dylib and libvtkRenderingCorePython35D-<wbr>8.1.dylib), are separate from each other. And also otool (on Mac) indicates that binaries actually point to the right parts. Also, I removed vtk otherwise from the system, so there is not a third version that interferes with the installation...

Do you have an idea where the problem comes from?

The error message by the way looks like this for me:

<pre>import vtk
------------------------------<wbr>------------------------------<wbr>---------------
ImportError                               Traceback (most recent call last)
/opt/dev/versions/vtk/vtk-8.1.<wbr>0-qt5-shared/lib/python3.5/<wbr>site-packages/vtk/<wbr>vtkFiltersPython.py in <module>()
      4     # use relative import for installed modules
----> 5     from .vtkFiltersPythonPython import *
      6 except ImportError:

ImportError: dlopen(/opt/dev/versions/vtk/<wbr>vtk-8.1.0-qt5-shared/lib/<wbr>python3.5/site-packages/vtk/<wbr>vtkFiltersPythonPython.so, 2): Symbol not found: __Py_ZeroStruct
  Referenced from: /opt/dev/versions/vtk/vtk-8.1.<wbr>0-qt5-shared/lib/<wbr>libvtkWrappingPython27Core-8.<wbr>1.1.dylib
  Expected in: flat namespace
 in /opt/dev/versions/vtk/vtk-8.1.<wbr>0-qt5-shared/lib/<wbr>libvtkWrappingPython27Core-8.<wbr>1.1.dylib

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-1-b7e11aadda62> in <module>()
----> 1 import vtk

/opt/dev/versions/vtk/vtk-8.1.<wbr>0-qt5-shared/lib/python3.5/<wbr>site-packages/vtk/__init__.py in <module>()
     48 from .vtkFiltersPoints import *
     49 from .vtkFiltersProgrammable import *
---> 50 from .vtkFiltersPython import *
     51 from .vtkFiltersSMP import *
     52 from .vtkFiltersSelection import *

/opt/dev/versions/vtk/vtk-8.1.<wbr>0-qt5-shared/lib/python3.5/<wbr>site-packages/vtk/<wbr>vtkFiltersPython.py in <module>()
      7     # during build and testing, the modules will be elsewhere,
      8     # e.g. in lib directory or Release/Debug config directories
----> 9     from vtkFiltersPythonPython import *

ImportError: No module named 'vtkFiltersPythonPython'
</pre>

Many thanks for any hints on this!
<br></blockquote></div><br></div></div>