Jupyter Notebook 显示小部件时的 JavaScript 错误

1 投票
1 回答
114 浏览
提问于 2025-04-12 18:27

我现在正在做一个使用 ydata_profiling 库的EDA项目。

这是我目前写的代码:

import numpy as np
import pandas as pd
from ydata_profiling import ProfileReport

profile = ProfileReport(df, title='Pandas Profiling Report', explorative=True)

profile.to_widgets() 

当我使用 .to_widgets() 这个代码时,会显示出我的数据总结,但在变量部分我遇到了一个javascript错误:

[Open Browser Console for more detailed log - Double click to close this message]
Model class 'AccordionModel' from module '@jupyter-widgets/controls' is loaded but can not be instantiated
Error: widget model not found 
at f.get_model (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/336.0a90bd910629a565bb7e.js?v=0a90bd910629a565bb7e:1:3460)
    at P (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/595.998263bfa9875eeeb29b.js?v=998263bfa9875eeeb29b:1:6289)
    at Object.P [as deserialize] (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/595.998263bfa9875eeeb29b.js?v=998263bfa9875eeeb29b:1:6099)
    at kt._deserialize_state (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/595.998263bfa9875eeeb29b.js?v=998263bfa9875eeeb29b:1:12378)
    at f._make_model (http://localhost:8888/lab/extensions/@jupyter-widgets/jupyterlab-manager/static/336.0a90bd910629a565bb7e.js?v=0a90bd910629a565bb7e:1:7932)
Report generated by YData.

我非常希望能得到一些建议或解决办法。

解决方案:请不要忽视更新你的jupyter notebook版本。我更新了整个jupyter notebook环境并重新加载,问题就解决了。可以运行以下命令:

jupyter notebook --version

pip install --upgrade notebook

1 个回答

0

Jupyter Lab 显示小部件的问题(javascript 错误) 收到了几个相关的回答,但没有哪个回答能单独解决问题。这表明:

所以,第一步是确保整个环境都是最新的,从 conda 开始,然后更新 Jupyter 和 ipywidgets。


几点注意事项:

  • 注意:因为你在使用 conda,所以要坚持使用 conda,不要混用一些pip命令,因为这样会导致安装的东西不在同一个地方,可能会出问题。
  • 既然要更新,考虑从 Jupyter 转到JupyterLab

撰写回答