Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JupyterLab: Failed to load model class 'AnyModel' from module 'anywidget' #725

Closed
Kreijstal opened this issue Nov 19, 2024 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@Kreijstal
Copy link

Kreijstal commented Nov 19, 2024

Describe the bug

installed anywidget using
pip install "anywidget[dev]"
Then went ahead and tried to counter example:

import anywidget
import traitlets

class CounterWidget(anywidget.AnyWidget):
    # Widget front-end JavaScript code
    _esm = """
    function render({ model, el }) {
      let button = document.createElement("button");
      button.innerHTML = `count is ${model.get("value")}`;
      button.addEventListener("click", () => {
        model.set("value", model.get("value") + 1);
        model.save_changes();
      });
      model.on("change:value", () => {
        button.innerHTML = `count is ${model.get("value")}`;
      });
      el.appendChild(button);
    }
    export default { render };
    """
    # Stateful property that can be accessed by JavaScript & Python
    value = traitlets.Int(0).tag(sync=True)

Reproduction

Since in the documentation it wasn't shared how to use it I assumed it was like this

counter=CounterWidget()
counter

Logs

[Open Browser Console for more detailed log - Double click to close this message]
Failed to load model class 'AnyModel' from module 'anywidget'
loadClass@http://127.0.0.1:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/134.a63a8d293fb35a52dc25.js?v=a63a8d293fb35a52dc25:1:74936
loadModelClass@http://127.0.0.1:8888/lab/extensions/@jupyter-widgets/jupyterlab-ma

In dev tools:

Error: No version of module anywidget is registered

System Info

$ npx envinfo --system --browsers
(node:19624) ExperimentalWarning: CommonJS module C:\Users\kreij\scoop\apps\msys2\2022-01-28\mingw64\lib\node_modules\npm\node_modules\debug\src\node.js is loading ES Module C:\Users\kreij\scoop\apps\msys2\2022-01-28\mingw64\lib\node_modules\npm\node_modules\supports-color\index.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Need to install the following packages:
envinfo@7.14.0
Ok to proceed? (y) y


  System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
    Memory: 3.42 GB / 15.79 GB
  Browsers:
    Edge: Chromium (127.0.2651.74), ChromiumDev (127.0.2610.3)
    Internet Explorer: 11.0.19041.4355

npx envinfo totally ignored the fact that I only use firefox, hilarious.

$ pip freeze | grep -E "anywidget|jupyter|notebook"
anywidget==0.9.13
jupyter-cache==1.0.0
jupyter-events==0.10.0
jupyter-lsp==2.2.5
jupyter_client==8.6.3
jupyter_core==5.7.2
jupyter_server==2.14.2
jupyter_server_terminals==0.5.3
jupyterlab==4.2.5
jupyterlab_pygments==0.3.0
jupyterlab_server==2.27.3
notebook_shim==0.2.4

Severity

blocking all usage of anywidget

@Kreijstal Kreijstal added the bug Something isn't working label Nov 19, 2024
@Kreijstal
Copy link
Author

Solved it, not sure if it's by restarting the system or because I patched cpython
msys2-contrib/cpython-mingw#183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant