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/versions/vtk/vtk-8.1.0-qt5-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_INSTALL_DIR" \
                  -DCMAKE_MACOSX_RPATH=ON \
                  -DCMAKE_INSTALL_RPATH="$VTK_INSTALL_DIR/lib" \
                  -DVTK_PYTHON_VERSION=3 \
                  -DPYTHON_EXECUTABLE="/Library/Frameworks/Python.framework/Versions/3.5/bin/python3" \
                  -DPYTHON_INCLUDE_DIR="/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m/" \
                  -DPYTHON_LIBRARY="/Library/Frameworks/Python.framework/Versions/3.5/lib/libpython3.5.dylib" \
                  -DVTK_Group_Qt=ON \
                  -DVTK_QT_VERSION=5 \
                  -DCMAKE_PREFIX_PATH="$QT_DIR/.."
ninja
ninja install
</pre>

<pre>mkdir build-python2.7
cd build-python2.7
# Same installation target!
VTK_INSTALL_DIR="/opt/dev/versions/vtk/vtk-8.1.0-qt5-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_INSTALL_DIR" \
                  -DCMAKE_MACOSX_RPATH=ON \
                  -DCMAKE_INSTALL_RPATH="$VTK_INSTALL_DIR/lib" \
                  -DVTK_PYTHON_VERSION=2 \
                  -DPYTHON_EXECUTABLE="/Library/Frameworks/Python.framework/Versions/2.7/bin/python2" \
                  -DPYTHON_INCLUDE_DIR="/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/" \
                  -DPYTHON_LIBRARY="/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib" \
                  -DVTK_Group_Qt=ON \
                  -DVTK_QT_VERSION=5 \
                  -DCMAKE_PREFIX_PATH="$QT_DIR/.."</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/python2.7/site-packages; python -c "import vtk"  # No error
cd $VTK_INSTALL_DIR_PY3/lib/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-8.1.dylib and libvtkRenderingCorePython35D-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
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/opt/dev/versions/vtk/vtk-8.1.0-qt5-shared/lib/python3.5/site-packages/vtk/vtkFiltersPython.py in <module>()
      4     # use relative import for installed modules
----> 5     from .vtkFiltersPythonPython import *
      6 except ImportError:

ImportError: dlopen(/opt/dev/versions/vtk/vtk-8.1.0-qt5-shared/lib/python3.5/site-packages/vtk/vtkFiltersPythonPython.so, 2): Symbol not found: __Py_ZeroStruct
  Referenced from: /opt/dev/versions/vtk/vtk-8.1.0-qt5-shared/lib/libvtkWrappingPython27Core-8.1.1.dylib
  Expected in: flat namespace
 in /opt/dev/versions/vtk/vtk-8.1.0-qt5-shared/lib/libvtkWrappingPython27Core-8.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.0-qt5-shared/lib/python3.5/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.0-qt5-shared/lib/python3.5/site-packages/vtk/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/><hr align="left" width="300" />
Sent from the <a href="http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html">VTK - Users mailing list archive</a> at Nabble.com.<br/>