Skip to content

fix: auto-detect Jupyter kernel to avoid blank trame renders#548

Open
dipinknair wants to merge 5 commits into
mainfrom
fix/backend
Open

fix: auto-detect Jupyter kernel to avoid blank trame renders#548
dipinknair wants to merge 5 commits into
mainfrom
fix/backend

Conversation

@dipinknair

@dipinknair dipinknair commented Jun 17, 2026

Copy link
Copy Markdown

Bug: plot() renders blank after installing pyvista[jupyter]

Root cause

Installing pyvista[jupyter] sets PyVista's global Jupyter backend to "trame".
PyVistaInterface.show() passed jupyter_backend=None straight through to
pv.Plotter.show(), so it silently inherited "trame", which tries to spin up
a local trame server. VS Code notebooks cannot render the resulting widget —
producing a blank output and a JS SyntaxError: Unexpected token ':'.

Fix

In PyVistaInterface.show() (pyvista_interface.py),
before calling pv.Plotter.show(), detect whether the code is running inside a
Jupyter kernel and default jupyter_backend to "static":

elif jupyter_backend is None:
    try:
        from IPython import get_ipython
        _ip = get_ipython()
        if _ip is not None and "IPKernelApp" in _ip.config:
            jupyter_backend = "static"
    except Exception:
        pass

"static" renders an inline PNG — no server required, works in VS Code,
JupyterLab, and Spyder.

Behaviour after fix

Scenario Backend used
Doc build (USE_HTML_BACKEND) "html" (unchanged)
Jupyter kernel, no explicit backend "static" (new default)
User passes jupyter_backend="trame" "trame" (explicit override respected)
Plain script / Qt unchanged pass-through

@github-actions github-actions Bot added maintenance Package and maintenance related bug Something isn't working labels Jun 17, 2026
Comment on lines +468 to +480
elif jupyter_backend is None:
# Auto-detect a Jupyter kernel and fall back to a safe static backend.
# Without this, PyVista defaults to "trame" (after installing
# pyvista[jupyter]), which spawns a local server and renders blank
# in VS Code / Spyder embedded notebooks.
try:
from IPython import get_ipython

_ip = get_ipython()
if _ip is not None and "IPKernelApp" in _ip.config:
jupyter_backend = "static"
except Exception:
pass

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change we would force static renderings on Jupyter NB. And PyVista (via trame) supports interactive ones. Let's try to figure out why it's not rendering on the user's machine.

We could have some kind of fallback though in the sense that if the render goes blank (i.e. fails) we attempt to render it statically. But not by default I'd say. Thanks for investigating @dipinknair

@AlejandroFernandezLuces can you sync with @dipinknair to investigate the issue? He'll share details on the user's failure

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll check on my end

@AlejandroFernandezLuces

Copy link
Copy Markdown
Collaborator

Just for the record, this is an issue we have had before with PyVista. Since the change to Trame, visualization in Jupyter and in our docs by extension has been difficult. Using PyVista and following the guide they have for using Trame and Jupyter, I'm not able to render anything on screen, I just get the loading screen:

image

The alternative that we can do is to fall back to HTML backend when in a Jupyter environment. It's does not have the full Trame functionality but at least it has a basic interactive 3D scene.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working maintenance Package and maintenance related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants