K3D-tools / K3D-jupyter

K3D lets you create 3D plots backed by WebGL with high-level API (surfaces, isosurfaces, voxels, mesh, cloud points, vtk objects, volume renderer, colormaps, etc). The primary aim of K3D-jupyter is to be easy for use as stand alone package like matplotlib, but also to allow interoperation with existing libraries as VTK.
MIT License
917 stars 123 forks source link

K3D fails in JupyterLab with jupyterlab_widgets=3? #371

Closed jatentaki closed 6 months ago

jatentaki commented 1 year ago

Description

There is an issue with K3D alongside the latest versions of jupyterlab. Running with jupyterlab_widgets=3.* (default, currently latest) causes JS crashes, whereas manually setting to 1.1 works. The crash manifests itself first in the console

jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2 Plugin 'jupyter.extensions.k3d' failed to activate.
(anonymous) @ jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2

and then in a JS error in the notebook image Clicking opens this: image

What I Did

To reproduce, I create an empty env with conda create -n k3d-test python=3.8 numpy, activate it and then

  1. For the failing version, execute pip install jupyterlab k3d
  2. For the working version, execute pip install jupyterlab k3d jupyterlab-widgets==1.1

Web console log / python logs

Text content of the error show in notebook:

[Open Browser Console for more detailed log - Double click to close this message]
Failed to load model class 'PlotModel' from module 'k3d'
loadClass@http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.083e6b37f2f7b2f04b5e.js?v=083e6b37f2f7b2f04b5e:1:74855
loadModelClass@http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.467514c324d2bcc23502.js?v=467514c324d2bcc23502:1:10721
_make_model@http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.467514c324d2bcc23502.js?v=467514c324d2bcc23502:1:7517
new_model@http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.467514c324d2bcc23502.js?v=467514c324d2bcc23502:1:5137
handle_comm_open@http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/150.467514c324d2bcc23502.js?v=467514c324d2bcc23502:1:3894
134/v/this._handleCommOpen@http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.083e6b37f2f7b2f04b5e.js?v=083e6b37f2f7b2f04b5e:1:73392
_handleCommOpen@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:994422
async*_handleMessage@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:996423
async*19883/b/this._onWSMessage/this._msgChain<@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:984339
promise callback*19883/b/this._onWSMessage@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:984324
EventHandlerNonNull*19883/b/this._createSocket@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:983870
b@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:985694
connectTo@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1004939
57847/d/this._connectToKernel@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1029974
setupKernel@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1027416
a@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1025256
connectTo@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1030739
_initialize@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:105591
async*initialize@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:105251
17454/_populate/<@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:478398
promise callback*_populate@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:478095
17454/_revert/<@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:480420
promise callback*_revert@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:480000
initialize@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:474758
async*69993/_createOrOpenDocument/d<@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:462540
promise callback*_createOrOpenDocument@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:462528
open@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:460596
openOrReveal@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:460749
87144/H/execute/<@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:442835
promise callback*execute@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:442823
45159/e.prototype.execute@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1353918
51156/restore/l<@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1152443
restore@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1152341
async*restore@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:84019
restore@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:21511
Q@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:781873
80885/e.prototype.activatePlugin/n.promise<@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1347126
promise callback*80885/e.prototype.activatePlugin@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1347090
80885/e.prototype.resolveRequiredService@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1347519
80885/e.prototype.activatePlugin/r<@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1346946
80885/e.prototype.activatePlugin@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1346920
80885/e.prototype.resolveRequiredService@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1347519
80885/e.prototype.activatePlugin/r<@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1346946
80885/e.prototype.activatePlugin@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1346920
80885/e.prototype.start/o<@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1348112
80885/e.prototype.start@http://localhost:8888/static/lab/jlab_core.9193dfb13484acaca919.js?v=9193dfb13484acaca919:2:1348086
G@http://localhost:8888/static/lab/7796.80e6d936dca84c219c9e.js?v=80e6d936dca84c219c9e:1:8377
async*e@http://localhost:8888/static/lab/main.357caa106b0f0fb27cf2.js?v=357caa106b0f0fb27cf2:1:1074
async*37559@http://localhost:8888/static/lab/main.357caa106b0f0fb27cf2.js?v=357caa106b0f0fb27cf2:1:1101
a@http://localhost:8888/static/lab/main.357caa106b0f0fb27cf2.js?v=357caa106b0f0fb27cf2:1:11188
@http://localhost:8888/static/lab/main.357caa106b0f0fb27cf2.js?v=357caa106b0f0fb27cf2:1:68844
@http://localhost:8888/static/lab/main.357caa106b0f0fb27cf2.js?v=357caa106b0f0fb27cf2:1:68853
flacle commented 1 year ago

Chiming in,

Also worked for me without reinstalling jupyterlab, but solely downgrading jupyterlab-widgets and ipywidgets.

pip uninstall jupyterlab-widgets ipywidgets
pip install ipywidgets==7.7.1 jupyterlab-widgets==1.1
renefritze commented 1 year ago

The examples on mybinderhub also seem broken. Dev console errors start with failing to load

https://hub.gke2.mybinder.org/user/k3d-tools-k3d-jupyter-etmiy3v5/static/k3d.js?v=20220907115548
tennysontbardwell commented 1 year ago

Pinning ipywidgets==7.7.1 jupyterlab-widgets==1.1 also worked for me

RonaldEnsing commented 1 year ago

I've got a similar problem:

[Open Browser Console for more detailed log - Double click to close this message] Model class 'PlotModel' from module 'k3d' is loaded but can not be instantiated

Pinning ipywidgets==7.7.1 and jupyterlab_widgets==1.1.0 did not work for me.

artur-trzesiok commented 1 year ago

Please try 2.15.0 (https://pypi.org/project/k3d/ for conda-forge we need to wait a little bit). @renefritze contribution should solve that

gonzalobg commented 1 year ago

@artur-trzesiok I've tried 2.15.2 and the hello world plot from the user guide as well as other examples (nbody) still fail with jupyterlab with errors like #384 .

Is 2.15.x supposed to work with jupyterlab?

artur-trzesiok commented 1 year ago

Yes it is

perllaghu commented 1 year ago

Aha.... this has answered a wee problem I was trying to solve - except I'm actually still running the classic UI.

My current versions, prepping for the 23/24 setup, are

jupyterlab 3.4.8
jupyterlab_widgets 3.0.7
k3d 2.15.2
notebook 6.4.12

The library is fine if I switch to the lab UI, but gives me the error in classic

If I compare this to my 22/23 setup - which has

jupyterlab 3.3.4
jupyterlab_widgets 1.1.1
k3d 2.13.1
notebook 6.4.11

.... jupyterlab_widgets is the big change

artur-trzesiok commented 6 months ago

I believe that this issue is very old and jupyter changed a api so probably it is no longer valid.

thomasXwang commented 1 month ago

I had the same issue: Failed to load model class 'PlotModel' from module 'k3d'

Updating ipywidgets and jupyterlab_widgets to the versions below solved the issue for me: pip install jupyterlab-widgets==3.0.9 ipywidgets==8.1.1