Troubleshooting a render window not showing up.

I usually output to file, so if this is obvious, my apologies.

I can copy-paste this example, and it works just fine: a window pops up with a cone in it. I tried to simplify it a bit and run it, and this code exits immediately, with no window shown and no error?

from vtkmodules.vtkFiltersSources import vtkConeSource
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleTrackballCamera
from vtkmodules.vtkRenderingCore import (
    vtkActor,
    vtkPolyDataMapper,
    vtkRenderer,
    vtkRenderWindow,
    vtkRenderWindowInteractor)

t = vtkConeSource()
mapper = vtkPolyDataMapper()
mapper.SetInputConnection(t.GetOutputPort())
actor = vtkActor()
actor.SetMapper(mapper)

ren = vtkRenderer()
ren.AddActor(actor)
ren_win = vtkRenderWindow()
ren_win.AddRenderer(ren)
ren_win.SetSize(640, 480)
ren_win.SetWindowName("Test")
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(ren_win)

ren_win.Render()
iren.Start()

Add these, they are the modules that contain the platform-specific implementions of vtkRenderWindow and vtkRenderWindowInteractor:

import vtkmodules.vtkRenderingOpenGL2
import vtkmodules.vtkRenderingUI

Without these, calling vtkRenderWindow() and vtkRenderWindowInteractor() creates objects that can’t render or interact because they can’t talk to the display.

But after importing e.g. vtkRenderingOpenGL2, vtkRenderWindow() will return an instance of the appropriate vtkRenderWindow subclass for rendering with OpenGL on your operating system. This is due to VTK’s factory mechanism. It’s a “feature” of VTK that you can override vtkRenderWindow by dynamically importing a module.

Ok - adding those two imports caused my script above to work. I tried it again with only import vtkmodules.vtkRenderingOpenGL2 and that worked as well.

Thanks