vtkRenderWindow from VTK 9.1.0 does not open from python 3.10.2 on M1 macbook on macOS 12.1

This simple tutorial code will not run correctly on my computer
https://kitware.github.io/vtk-examples/site/Python/Tutorial/Tutorial_Step1/

I’m running in a conda environment with:
python 3.10.2
vtk 9.1.0
on macOS Monterey 12.1

When I run it on my Linux desktop it works fine, there conda installs python 3.9.7 and vtk 9.0.3

I tried using python 3.9.7 and vtk 9.0.3 in my conda environment on mac and had the same issue.

The code runs without error and exits, but no window is ever opened.

Which seems to indicate that the vtkRenderWindow object is failing to open a window.

I can get a window to open by adding a vtkRenderWindowInteractor() object as is shown in this example
https://kitware.github.io/vtk-examples/site/Python/GeometricObjects/CylinderExample/

I am hesitant to continue trying to work with this on my macbook if it seems that some core functionality is just failing to work.

Can anybody replicate this issue?

I am seeing this on my 2015 macbook pro

Looking at https://vtk.org/download/,
there are only wheels for python 3.6 - 3.9. I don’t think python 3.10 is supported, unless Conda is doing something extra…

That is an interesting point. There are definitely vtk packages marked for python 3.10 when I search conda:

I just tried creating a fresh environment using python 3.9 and a suitable vtk version with the same result.

The first tutorial step runs without error but no window is shown.

Rerunning with an interactive render window results in the window being shown.

Actually that is expected as some VTK factories don’t get properly initialized.
You need to do the following imports to properly initialize it. The interactor style is probably not required for that specific example though.

This behavior is expected?

I’m not sure what you mean by that, I included the imports you mention. Although it should be noted that

import vtkmodules.vtkInteractionStyle
import vtkmodules.vtkRenderingOpenGL2

Are already part of the example code I linked in the OP. replacing with

from vtkmodules.vtkInteractionStyle import vtkInteractorStyleSwitch
import vtkmodules.vtkRenderingOpenGL2

makes no difference

I’m glad this topic is getting some discussion now that someone else has replicated the issue. I imagine it has something to do with macOS

Thanks for the response Sebastien. I can confirm Pierre’s finding that the added imports made no change.

I guess I missed to see those import in that example.

Can you try outside of conda because for me the pip vtk is working fine on 3.9 on my mac.

python3.9 -m venv test-vtk
source ./test-vtk/bin/activate
pip install -U pip
pip install vtk
python ./example-vtk-script.py

I just followed your steps and the result was the same for me, no window opened and program terminates without error

Although I did receive the following warning in stdout

2022-04-07 09:10:45.648 Python[28107:7375278] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/5z/d1d_q74d1hd653s14vwq9v800000gn/T/org.python.python.savedState

A quick google search shows that this is a common warning when launching a window from python on macos. So it seems that at least there is some indication that the program is trying to launch a window.

What version of macos are you using? I am on version 12.1, also curious what version @bfosso is using

I left conda, installed python 3.9 with brew and followed your steps.

The program ran without error but no window opened.

I did NOT see an error message.

I am on macOS 12.3.

I am using vtk 9.1.0 installed via pip, python 3.9 and macOS 11.5.

This example does create a window without error on my system.

However, I often use render windows within Jupyter notebooks. On mac, this example crashes the notebooks, even though it works ok on windows.

I am having the same issue with VTK 9.2.20230422/Python 3.8.12/Jupyter-lab 3.2.8/MacOS12.6.3: When running tutorial 1 from jupyterlab, without the interactor, the window will not open on renWin.Render(), even though

print(renWin)

vtkCocoaRenderWindow (0x150617830)
Debug: Off
Modified Time: 1065
Reference Count: 2
Registered Events: (none)
Erase: On
Window Name: Visualization Toolkit - Cocoa #1
Position: (50, 220)
Size: (1500, 1500)
Mapped: 1
ShowWindow: 1
UseOffScreenBuffers: 0
Double Buffered: 1
DPI: 72
TileScale: (1, 1)
TileViewport: (0, 0, 1, 1)
Borders: On
Double Buffer: On
Full Screen: Off
Renderers:
Debug: Off
Modified Time: 195
Reference Count: 1
Registered Events: (none)
Number Of Items: 1
Stereo Capable Window Requested: No
Stereo Render: Off
Point Smoothing: Off
Line Smoothing: Off
Polygon Smoothing: Off
Abort Render: 0
Current Cursor: 0
Desired Update Rate: 0.0001
In Abort Check: 0
NeverRendered: 0
Interactor: 0x15070ec00
Swap Buffers: On
Stereo Type: RedBlue
Number of Layers: 1
AlphaBitPlanes: On
UseSRGBColorSpace: Off
AnaglyphColorSaturation: 0.65
AnaglyphColorMask: 4 , 3
MultiSamples: 0
StencilCapable: False
CocoaManager: 0x6000031b0180
RootWindow (NSWindow): 0x104204b30
WindowId (NSView): 0x1042046c0
ParentId (NSView): 0x0
ContextId: 0x6000031807c0
PixelFormat: 0x6000033b8690
WindowCreated: Yes
ViewCreated: Yes
WantsBestResolution: Yes

When an interactor is added, the window opens, and the keyboard commands work. However, on (q)quite/(e)xit, the render window will stay open even though other cells can now be executed. Mousing over it will show the spinning wheel cursor. While minimization (yellow button) works, the red one does not. The only way to get rid of the window seems to be to restart the kernel.

iren.GetRenderWindow().Finalize() 
iren.TerminateApp()
del renWin, iren

executes w/o error, and renWin and iren are deleted, but the window remains open.