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

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

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.