0%

jupyter lab plotly画图空白不显示的问题

使用jupyter lab画图时,图片不显示而显示空白。


说一下目前最新版本的处理情况。

python base环境

1
2
python                    3.12.5
jupyterlab 4.2.5

python env py310环境

1
2
python                    3.10.15
plotly 5.20.0

本来只需要在base环境再安装jupyterlab-plotly插件就行了,但会报错,提示版本不匹配。
所以解决方案,就是在base环境再安装一下相同版本号的plotly。安装好了以后,再查看插件jupyterlab-plotly,就已经同时安装成功了。

1
2
3
4
5
6
$ jupyter labextension list
JupyterLab v4.2.5
/Users/simon/miniforge3/share/jupyter/labextensions
jupyterlab_pygments v0.3.0 enabled OK (python, jupyterlab_pygments)
jupyterlab-plotly v5.24.1 enabled X 🔒 (all plugins locked)
@jupyter-widgets/jupyterlab-manager v5.0.13 enabled OK (python, jupyterlab_widgets)

这时,重新启动jupyter lab,plotly的图形就可以正常显示了。


首先要确保的是以下两个库jupyterlabipywidgets已经安装完成,并且版本”jupyterlab>=3” “ipywidgets>=7.6”。

需要安装一个扩展工具。一般来说,JupyterLab 3.x以上,会自动安装好,并且是安装在JupyterLab被安装的Python环境下面。

1
$ jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyterlab-plotly

安装完可以查看一下。

1
2
# Check that jupyterlab-plotly is installed
$ jupyter labextension list

这个工具需要依赖nodejs,如果没有安装的话,需要安装一下。

1
$ conda install nodejs

重启jupyter lab,图片即可正常显示。

有几个点需要注意的是:

jupyterlab以及jupyterlab的extension是安装在server端的,但是plotly包是安装在其他python环境里面的。