pyvista / pyvista

3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK)

Home Page:https://docs.pyvista.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Interactive plot cannot be shown in Jupyter

YongcaiHuang opened this issue · comments

Describe the bug, what's wrong, and what you expected.

I found a bug!

UserWarning: Failed to use notebook backend: cannot import name 'vtk' from 'trame.widgets'

pyvista: 0.43.4
vtk: 9.3.0

MacOS Sonoma 14.4.1

Steps to reproduce the bug.

# examples
from pyvista import examples
mesh = examples.download_dragon()
mesh['scalars'] = mesh.points[:, 1]
mesh.plot(cpos='xy', cmap='plasma')

System Information

--------------------------------------------------------------------------------
  Date: Tue Apr 02 18:54:52 2024 CST

                OS : Darwin
            CPU(s) : 10
           Machine : arm64
      Architecture : 64bit
               RAM : 16.0 GiB
       Environment : Jupyter
       File system : apfs
        GPU Vendor : Apple
      GPU Renderer : Apple M2 Pro
       GPU Version : 4.1 Metal - 88
  MathText Support : True

  Python 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:26:40)
  [Clang 14.0.6 ]

           pyvista : 0.43.4
               vtk : 9.3.0
             numpy : 1.26.4
        matplotlib : 3.8.3
            scooby : 0.9.2
             pooch : 1.8.1
            pillow : 10.2.0
           imageio : 2.34.0
           IPython : 8.22.2
        ipywidgets : 8.1.2
             scipy : 1.12.0
              tqdm : 4.66.2
        jupyterlab : 4.1.5
             trame : 3.4.0
      trame_client : 2.16.5
      trame_server : 2.17.2
      nest_asyncio : 1.6.0
--------------------------------------------------------------------------------

Screenshots

No response

I got the similar problem, which shown in the following picture.
Screenshot from 2024-04-02 19-06-21
If I install trame-vtk and trame-vuetify, a new problem will be here:
3

my environment running with jupyter-notebook in docker container:
pip list| grep jupyter imjoy-jupyter-extension 0.3.0 jupyter-client 8.6.1 jupyter-core 5.7.2 jupyter-events 0.10.0 jupyter-server 2.13.0 jupyter-server-proxy 4.1.2 jupyter-server-terminals 0.5.3 jupyterlab-pygments 0.1.2 jupyterlab-widgets 3.0.10
pip list| grep trame trame 3.5.4 trame-client 2.16.5 trame-server 2.17.2 trame-vtk 2.8.5 trame-vuetify 2.4.3

pyvista 0.43.4
python:3.8.5 ubuntu18.04

probably you did not installed pyvista with the jupyter option (pip install "pyvista[jupyter]")

probably you did not installed pyvista with the jupyter option (pip install "pyvista[jupyter]")

@jourdain
thanks for yoour reply. After installing with the jupyter option (pip install "pyvista[jupyter]"), I found the trame-vtk and trame-vuetify will be installed too. I would get the error
3
And I found some requests in F12 like "http://localhost:41349/index.html?ui=P_0x7f245835a970_0&reconnect=auto", a new port will be generated dynamically ? In container, the dynamic port cannot be forwarded to outside. Is there a solution? thks again

@jxfruit For me keeping the normal pyvista installation with additional packages trame-vtk , trame-vuetify and ipywidgets fixed the issue. Had to restart the kernal though. However, I am using the VSCode to run the notebook.

You can install trame-jupyter-extension or leverage the jupyter proxy server.

probably you did not installed pyvista with the jupyter option (pip install "pyvista[jupyter]")

thanks for your comments! it works in JupyterLab browser. However, I found it cannot be shown on JupyterLab desktop. I am not sure if the problem is with the JupyterLab desktop.

image
Error handling request
Traceback (most recent call last):
  File "[/opt/homebrew/anaconda3/envs/pip/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 350](http://localhost:56562/opt/homebrew/anaconda3/envs/pip/lib/python3.10/site-packages/aiohttp/web_protocol.py#line=349), in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
  File "aiohttp[/_http_parser.pyx", line 557](http://localhost:56562/_http_parser.pyx#line=556), in aiohttp._http_parser.HttpParser.feed_data
  File "aiohttp[/_http_parser.pyx", line 732](http://localhost:56562/_http_parser.pyx#line=731), in aiohttp._http_parser.cb_on_header_value
aiohttp.http_exceptions.LineTooLong: 400, message:
  Got more than 8190 bytes (55572) when reading Header value is too long.

Might be an issue with message size on the websocket. You can try to bump trame>=3.6 which should fix message size.

Might be an issue with message size on the websocket. You can try to bump trame>=3.6 which should fix message size.

Hi, I tried to upgrade the trame, but it still cannot be rendered.

env list

abirami-hide-code 4.0.5
aiohttp 3.9.5
aiosignal 1.3.1
anyio 4.3.0
appnope 0.1.4
argon2-cffi 23.1.0
argon2-cffi-bindings 21.2.0
arrow 1.3.0
asttokens 2.4.1
async-lru 2.0.4
async-timeout 4.0.3
attrs 23.2.0
Babel 2.14.0
beautifulsoup4 4.12.3
bleach 6.1.0
bqplot 0.12.43
certifi 2024.2.2
cffi 1.16.0
charset-normalizer 3.3.2
comm 0.2.2
contourpy 1.2.1
cycler 0.12.1
debugpy 1.8.1
decorator 5.1.1
defusedxml 0.7.1
exceptiongroup 1.2.1
executing 2.0.1
fastjsonschema 2.19.1
fonttools 4.51.0
fqdn 1.5.1
frozenlist 1.4.1
h11 0.14.0
httpcore 1.0.5
httpx 0.27.0
idna 3.7
imageio 2.34.1
ipydatawidgets 4.3.5
ipykernel 6.29.4
ipympl 0.9.4
ipython 8.24.0
ipython-genutils 0.2.0
ipyvolume 0.6.1
ipyvue 1.11.1
ipyvuetify 1.9.4
ipywebrtc 0.6.0
ipywidgets 8.1.2
isoduration 20.11.0
itables 2.0.1
jedi 0.19.1
Jinja2 3.1.3
joblib 1.4.2
json5 0.9.25
jsonpointer 2.4
jsonschema 4.22.0
jsonschema-specifications 2023.12.1
jupyter 1.0.0
jupyter_client 8.6.1
jupyter-console 6.6.3
jupyter_core 5.7.2
jupyter-events 0.10.0
jupyter-lsp 2.2.5
jupyter_server 2.14.0
jupyter_server_proxy 4.1.2
jupyter_server_terminals 0.5.3
jupyterlab 4.1.8
jupyterlab-execute-time 3.1.2
jupyterlab-lsp 5.1.0
jupyterlab_pygments 0.3.0
jupyterlab_server 2.27.1
jupyterlab_widgets 3.0.10
jupytext 1.16.1
kiwisolver 1.4.5
lazy_loader 0.4
lckr_jupyterlab_variableinspector 3.2.1
markdown-it-py 3.0.0
MarkupSafe 2.1.5
matplotlib 3.8.4
matplotlib-inline 0.1.7
mdit-py-plugins 0.4.0
mdurl 0.1.2
mistune 3.0.2
more-itertools 10.2.0
msgpack 1.0.8
multidict 6.0.5
nbclient 0.10.0
nbconvert 7.16.4
nbformat 5.10.4
nest-asyncio 1.6.0
networkx 3.3
notebook 7.1.3
notebook_shim 0.2.4
numpy 1.26.4
overrides 7.7.0
packaging 24.0
pandas 2.2.2
pandas-flavor 0.6.0
pandocfilters 1.5.1
parso 0.8.4
patsy 0.5.6
pexpect 4.9.0
pillow 10.3.0
pingouin 0.5.4
pip 24.0
platformdirs 4.2.1
plotly 5.22.0
pooch 1.8.1
prometheus_client 0.20.0
prompt-toolkit 3.0.43
psutil 5.9.8
ptyprocess 0.7.0
pure-eval 0.2.2
pycparser 2.22
Pygments 2.17.2
pyparsing 3.1.2
PySide6 6.7.0
PySide6_Addons 6.7.0
PySide6_Essentials 6.7.0
python-dateutil 2.9.0.post0
python-json-logger 2.0.7
pythreejs 2.4.2
pytz 2024.1
pyvista 0.43.6
PyYAML 6.0.1
pyzmq 26.0.3
qtconsole 5.5.1
QtPy 2.4.1
referencing 0.35.1
requests 2.31.0
rfc3339-validator 0.1.4
rfc3986-validator 0.1.1
rpds-py 0.18.0
scikit-image 0.23.2
scikit-learn 1.4.2
scipy 1.13.0
scooby 0.9.2
seaborn 0.13.2
Send2Trash 1.8.3
setuptools 69.5.1
shiboken6 6.7.0
simpervisor 1.0.0
SimpleITK 2.3.1
six 1.16.0
sniffio 1.3.1
soupsieve 2.5
stack-data 0.6.3
statsmodels 0.14.2
tabulate 0.9.0
tenacity 8.2.3
terminado 0.18.1
threadpoolctl 3.5.0
tifffile 2024.4.24
tinycss2 1.3.0
toml 0.10.2
tomli 2.0.1
tornado 6.4
traitlets 5.14.3
traittypes 0.2.1
trame 3.6.0
trame-client 3.0.2
trame-server 3.0.0
trame-vtk 2.8.7
trame-vuetify 2.4.3
types-python-dateutil 2.9.0.20240316
typing_extensions 4.11.0
tzdata 2024.1
uri-template 1.3.0
urllib3 2.2.1
vtk 9.3.0
wcwidth 0.2.13
webcolors 1.13
webencodings 0.5.1
websocket-client 1.8.0
wheel 0.43.0
widgetsnbextension 4.0.10
wslink 2.0.2
xarray 2024.3.0
yarl 1.9.4

Thanks for trying, I guess I'm not sure where that issue with JupyterLab desktop is coming from.

@jxfruit For me keeping the normal pyvista installation with additional packages trame-vtk , trame-vuetify and ipywidgets fixed the issue. Had to restart the kernal though. However, I am using the VSCode to run the notebook.

It works in local environment. However, I use it in k8s container, a specific port is necessary.

You can install trame-jupyter-extension or leverage the jupyter proxy server.

it looks like that does not work in Jupyter notebook. It get the same error

image

When you are dealing with remote services, the default setting is not enough. Either you need to use jupyter-server-proxy or trame-jupyter-extension. With jupyter-server-proxy when not used within JupyterHub (which setup some ENV variable) you will need to set os.environ["TRAME_IFRAME_BUILDER"] = "serverproxy".

Had the same issue with a conda install. Installing pyvista with conda install -c conda-forge pyvista jupyterlab ipywidgets trame did not automatically add trame-vtk as a dependency, and I was getting the same error as @YongcaiHuang.
After installing trame-vtk and trame-vuetify as suggested by @savindi-wijenayaka, I'm able to load the widgets in Jupyterlab.