vtk build issue with QT and python wrapping

hi, i was trying to build vtk with QT and python wrappings turned on. The build completed successfully and even installation, but when i do import vtk in python i get error

Traceback (most recent call last):
File “/anaconda3/lib/python3.6/site-packages/vtkmodules/vtkRenderingQt.py”, line 5, in
from .vtkRenderingQtPython import *
ImportError: dlopen(/anaconda3/lib/python3.6/site-packages/vtkmodules/vtkRenderingQtPython.so, 2): Library not loaded: @rpath/QtWidgets.framework/Versions/5/QtWidgets
Referenced from: /usr/local/lib/libvtkRenderingQt-8.2.1.dylib
Reason: Incompatible library version: libvtkRenderingQt-8.2.1.dylib requires version 5.12.0 or later, but QtWidgets provides version 5.11.0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/Users/abhishek/Documents/python/spectre-v5/Spectre.py”, line 14, in
from controllers.ScanController import ScanController
File “/Users/abhishek/Documents/python/spectre-v5/controllers/ScanController.py”, line 6, in
import vtk
File “/anaconda3/lib/python3.6/site-packages/vtk.py”, line 32, in
all_spec.loader.exec_module(all_m)
File “/anaconda3/lib/python3.6/site-packages/vtkmodules/all.py”, line 100, in
from .vtkRenderingQt import *
File “/anaconda3/lib/python3.6/site-packages/vtkmodules/vtkRenderingQt.py”, line 9, in
from vtkRenderingQtPython import *
ModuleNotFoundError: No module named ‘vtkRenderingQtPython’

how can i fix this problem?

Thanks

You’ve built against a Qt 5.12, but at runtime, 5.11 is being found. The first error comes from the dynamic loader. The second is Python’s reaction to the loader saying “no”.

hi, i installed PyQt 5.12.2 and also built vtk with Qt 5.12.2, then i get this error when i try to run import vtk

Traceback (most recent call last):

File “/anaconda3/lib/python3.6/site-packages/vtkmodules/vtkRenderingQt.py”, line 5, in

*from .vtkRenderingQtPython import **

ImportError: dlopen(/anaconda3/lib/python3.6/site-packages/vtkmodules/vtkRenderingQtPython.so, 2): Library not loaded: @rpath/QtWidgets.framework/Versions/5/QtWidgets

Referenced from: /usr/local/lib/libvtkRenderingQt-8.2.1.dylib

Reason: image not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File “/Users/abhishek/Documents/python/test/read_vtk.py”, line 1, in

import vtk

File “/anaconda3/lib/python3.6/site-packages/vtk.py”, line 32, in

all_spec.loader.exec_module(all_m)

File “/anaconda3/lib/python3.6/site-packages/vtkmodules/all.py”, line 100, in

*from .vtkRenderingQt import **

File “/anaconda3/lib/python3.6/site-packages/vtkmodules/vtkRenderingQt.py”, line 9, in

*from vtkRenderingQtPython import **

ModuleNotFoundError: No module named ‘vtkRenderingQtPython’

have i missed some flag? both *vtkRenderingQtPython.so and *libvtkRenderingQt-8.2.1.dylib are in the paths above, what is the reason for image not found error?

thanks

It’s saying that it can’t find QtWidgets based on the information available in vtkRenderingQtPython.so. It’s probably missing an LC_RPATH command entry. This can be fixed by adding the path to the Qt frameworks to the CMAKE_INSTALL_RPATH and/or CMAKE_BUILD_RPATH variable(s) when building VTK depending on which you’re using in the end.

hi, if i try to run from vtkpython exec that was created in the build bin folder it works fine, so i tried to copy the contents of site-packages folder to anaconda root site-packages folder from that point on i am getting

Fatal Python error: PyThreadState_Get: no current thread

i am not able to understand how it is running fine from the vtkpython exec but not if i open a python terminal and try running it, it’s the same version of python in both cases, 3.6.5

thanks

Seems that Dan answered this specific question here: using vtk 8.2.0 with python wrappings with anaconda

hi,

in this case i am getting ModuleNotFoundError: No module named ‘vtkRenderingQtPython’ error, in the other case i am getting a different error, i thought since the errors were different i had to open different topics.

hence 2 different posts

Thanks

Ah, I see. If you’re seeing the Qt loader errors, that is the root problem. You’ll need to change CMAKE_INSTALL_RPATH and CMAKE_BUILD_RPATH to include the path to your Qt installation to make the @rpath/QtWidgets.framework/Versions/5/QtWidgets library lookup work.