libvtkRenderingTk-9.2.so : No such file or directory

Dear VTK developers,

I am encountering an issue with the libvtkRenderingTk-9.2.so library file when using VTK with Python. Specifically, I am receiving the following error message:

libvtkRenderingTk-9.2.so: cannot open shared object file: No such file or directory

I have followed the installation instructions provided in the VTK documentation. However, I am still encountering this error.

I would appreciate any assistance or guidance you can provide in resolving this issue. Please let me know if you require any additional information from me.

Thank you for your time and attention.

Sincerely

That library isn’t included in any of the VTK binary packages. VTK’s RenderingTk module is only available if it’s configured when VTK is built from source code.

I don’t understand; I am on ubuntu 20.04 and trying to build a GUI with Python 3.8.10, VTK 9.0.1, and Tkinter. Using VTK and Tkinter separately works well, but I struggle to combine them.

I have tried it with a vtkTkRenderWindowInteractor and a vtkTkRenderWidget so far, but I always obtain the error:

_tkinter.TclError: couldn’t load file “libvtkRenderingTk-9.0.so”: libvtkRenderingTk-9.0.so: cannot open shared object file: No such file or directory

That library, libvtkRenderingTk-9.2.so, is not included with the VTK binary packages. How did you install VTK 9.0.1? Was it pip, conda, or a .deb with apt-get? Or did you build VTK 9.0.1 from source code?

I tried installing VTK 9.0.1 with pip, and apt-get, but none of these methods seemed to include the libvtkRenderingTk-9.2.so library. Then, I tried to compile VTK 9.0.1 from source code, but I couldn’t resolve the issue of the missing library.

The pip package definitely doesn’t include libvtkRenderingTk-9.2.so, and I don’t think the deb does either.

For building from source, Tk must be enabled with VTK_USE_TK=ON. I recommend these options for VTK 9.0.1, it that’s the version of VTK that you need:

cmake -DCMAKE_CXX_COMPILER=/usr/bin/g++-9 -DCMAKE_C_COMPILER=/usr/bin/gcc-9 \
 -DBUILD_SHARED_LIBS=ON -DVTK_BUILD_TESTING=OFF -DVTK_PYTHON_VERSION=3 \
 -DCMAKE_BUILD_TYPE=Release -DVTK_WRAP_PYTHON=ON -DVTK_USE_TK=ON \
 ../VTK-9.0.1

It will also be necessary to use apt-get to install the tk-dev and tcl-dev packages before running cmake.

I am writing to provide an update on the issue I am encountering with the installation of vtk python.
As you recommended, I have installed the tk-dev and tcl-dev packages using the following commands:
sudo apt-get install tk-dev
sudo apt-get install tcl-dev

I then cloned the vtk repository and built VTK from source code using the options you provided:

git clone --recursive https://gitlab.kitware.com/vtk/vtk.git
cd vtk
mkdir build

cmake -DCMAKE_CXX_COMPILER=/usr/bin/g+±9 -DCMAKE_C_COMPILER=/usr/bin/gcc-9 -DBUILD_SHARED_LIBS=ON -DVTK_BUILD_TESTING=OFF -DVTK_PYTHON_VERSION=3 -DCMAKE_BUILD_TYPE=Release -DVTK_WRAP_PYTHON=ON -DVTK_USE_TK=ON …/vtk

Unfortunately, I am still encountering the error message “libvtkRenderingTk-9.0.so: cannot open shared object file: No such file or directory” when I try to install vtk python.

I wanted to inform you that I have already tried these steps and ask if you have any additional suggestions or recommendations for resolving this issue.

Thank you for your time and assistance.

Best regards,

In order to help me to resolve this for you, please to the following:

  1. Search your build tree for libvtkRenderingTk-9.0.so. It should be somewhere in the lib directory or one of the lib subdirectories. If it isn’t there, then we can see if other options must be added to ‘CMake’. The instructions that I provided were for VTK 9.0, I can’t remember if VTK master branch needs different options.
  2. If you can find libvtkRenderingTk-9.0.so, then the problem is that Python isn’t able to load it, you might be able to fix it by putting it somewhere in Tcl’s load path.

Thank you for your response. I have searched the build directory for the file libvtkRenderingTk-9.0.so, but I could not find it.

You can try adding this when you run cmake:

-DVTK_MODULE_ENABLE_VTK_RenderingTk=YES

Also, you can try to specifically build the library target when you run make:

 make RenderingTk

This creates libvtkRenderingTk-9.2.so, the error is about libvtkRenderingTk-9.0.so: cannot open shared object file: No such file or directory

Are you running a different VTK than the one you built?

Please show me the exact command-line that you run when you get the error.

Dear David Gobbi

I apologize for the confusion, the vtk is now correctly installed

I have attempted to use VTK to render the WRL file in a Tkinter frame, but I encountered some issues with the vtkTkRenderWindowInteractor widget.
Specifically, I received a “vtkTkRenderWindowInteractor object has no attribute ‘pack’” error message when I attempted to pack the widget in the frame.

Would you happen to know if there is a way to display a WRL file in a Tkinter frame using VTK or any other library? Any guidance or resources you could provide would be greatly appreciated.
Thank you for your time and assistance.

I look forward to hearing from you soon.

I don’t have a simple example for vtkTkRenderWindowInteractor, but I have one for vtkTkRenderWidget. This works on my linux system:

import tkinter
from vtkmodules.tk.vtkTkRenderWidget import vtkTkRenderWidget

from vtkmodules.vtkFiltersSources import vtkConeSource
from vtkmodules.vtkRenderingCore import vtkActor, vtkPolyDataMapper, vtkRenderer
# load implementations for rendering and interaction factory classes
import vtkmodules.vtkRenderingOpenGL2
import vtkmodules.vtkInteractionStyle

def vtkRenderWidgetConeExample():
    """Just a simple example.
    """
    # create root window
    root = tkinter.Tk()

    # create vtkTkRenderWidget
    pane = vtkTkRenderWidget(root,width=300,height=300)
    pane.bind('<Configure>', lambda e,pane=pane: pane.Expose())

    ren = vtkRenderer()
    pane.GetRenderWindow().AddRenderer(ren)

    cone = vtkConeSource()
    cone.SetResolution(8)

    coneMapper = vtkPolyDataMapper()
    coneMapper.SetInputConnection(cone.GetOutputPort())

    coneActor = vtkActor()
    coneActor.SetMapper(coneMapper)

    ren.SetBackground(0.0,0.3,0.1)
    ren.AddActor(coneActor)

    # pack the pane into the tk root
    pane.pack(expand='true', fill='both')

    # start the tk mainloop
    root.mainloop()

if __name__ == "__main__":
    vtkRenderWidgetConeExample()

In my linux system, I get the error:

2023-03-24 01:52:14.474 ( 0.079s) [ 9433D740] vtkTkRenderWidget.cxx:601 WARN| A TkRenderWidget is being destroyed before it associated vtkRenderWindow is destroyed.This is very bad and usually due to the order in which objects are being destroyed.Always destroy the vtkRenderWindow before destroying the user interface components.
Traceback (most recent call last):
File “wrl.py”, line 83, in
vtkRenderWidgetConeExample()
File “wrl.py”, line 33, in vtkRenderWidgetConeExample
pane = vtkTkRenderWidget(root,width=300,height=300)
File “/home/dell/.local/lib/python3.8/site-packages/vtkmodules/tk/vtkTkRenderWidget.py”, line 108, in init
tkinter.Widget.init(self, master, ‘vtkTkRenderWidget’, cnf, kw)
File “/usr/lib/python3.8/tkinter/init.py”, line 2572, in init
self.tk.call(
_tkinter.TclError

I need more information. Does it do this when you start the program, or does it do this when you quit the program?

It doesn’t happen when I run that program.

I am running the program on a Ubuntu 20.04 machine with Python 3.8. When I run the program using the command ‘python wrl.py’, I encounter the error message at the startup

That’s strange! Many years ago, I saw that error (TkRenderWidget is being destroyed before it associated vtkRenderWindow is destroyed.) but only when the program quit, never when the program started.

Are your running the VTK that you build from source? In the error message, it says File “/home/dell/.local/lib/python3.8/site-packages/vtkmodules/tk/vtkTkRenderWidget.py”, line 108, which looks like a directory for pip. If you are mixing parts of the VTK you build from source with a VTK that you installed with pip, then maybe that’s why you are getting an error.

Yes, you are right - I have successfully reinstalled VTK from the source code and it is now working perfectly.
Thank you for your previous guidance and support in helping me with this issue.
I am particularly grateful for how you took the time to answer all my questions and explain the technical details of the installation.