目前自己使用的几个插件,后续再更新。
jupyter 插件话题 topics:jupyterlab-extension
插件相关常用命令:
- 查看已安装插件:
jupyter labextension list
- 查看 serverextension:
jupyter serverextension list
- 更新已安装插件:
jupyter labextension update --all
注意:下面插件的安装方式和快捷键等配置会随版本变动,建议去官方 repo 中查看最新文档。
1. 插件前置环境 – node/npm
插件需要前置安装 nodejs 与 npm,推荐安装较新的版本,有的插件会要求新版本
此处采用解压官方编译的二进制包的方式安装。
- 官方下载地址 nodejs download,此处下载 Linux Binaries (x64)。
-
解压:
xz -d node-v12.19.0-linux-x64.tar.xz tar --strip-components 1 -xvf node-v12.19.0-linux-x64.tar.xz -C /usr/local
解压之后即可使用,但部分插件会需要使用 yarn,下面安装一下。
-
安装 yarn:
npm install -g yarn
- 不推荐更改 npm 镜像源,目前测试淘宝源发现部分插件的部分版本会找不到,建议保留官方默认镜像。
2. 插件推荐
2.1 jupyterlab-toc: 生成目录
此插件的功能将集成到 jupyterlab 3.0,即 3.0 以后不要在安装此插件。
jupyterlab/jupyterlab-toc:检索标题,生成目录树(注意: 每个标题都要在 cell 的首行)。
安装:
jupyter labextension install @jupyterlab/toc
效果图:
figure 1
2.2 jupyterlab_code_formatter
ryantam626/jupyterlab_code_formatter:代码格式化
安装:
- 安装 frontend:
jupyter labextension install @ryantam626/jupyterlab_code_formatter
查看插件版本:
jupyter labextension list | grep jupyterlab_code_formatter
- 安装格式化规范:
pip install isort black autopep8
- 安装 backend:
pip install jupyterlab_code_formatter==填写上面看到的版本
如果版本不一致,会导致插件无法使用!
-
启用:
jupyter serverextension enable --py jupyterlab_code_formatter
- 配置默认规范:
以 autopep8 为例。在 Settings -> Advanced Setting Editor -> Jupyterlab Code Formatter,下面内容放到 User Overrides 里
{ "preferences": { "default_formatter": { "python": "autopep8" } } }
- 配置快捷键:
以 autopep8 为例。在 Settings -> Advanced Setting Editor -> Keyboard Shortcuts,下面内容放到 User Overrides 里:
{ "shortcuts": [ { "command": "jupyterlab_code_formatter:autopep8", "keys": [ "Alt C" ], "selector": ".jp-Notebook.jp-mod-editMode" } ] }
2.3 plotly
plotly.py: 使 jupyterlab 内嵌 plotly 的图形,这样可以非常方便地图形交互。
安装:
pip install plotly # plotly 库
pip install ipywidgets # 插件依赖
jupyter labextension install jupyterlab-plotly # 插件
效果图:
这样可以使用右上角的工具操作绘制的图形。
2.4 jupyterlab-variableInspector
lckr/jupyterlab-variableInspector:在变量工作区就可以看到当前 notebook 中的变量、变量类型、变量大小等信息。
安装:
jupyter labextension install @lckr/jupyterlab_variableinspector
如果需要在 Inspector 里使用可交互的部件,那需要安装其他扩展,这里不再粘贴,见作者 repo 吧。
效果图:
⚡ myenv ~❯ jupyter labextension install @jupyterlab/toc
An error occured.
ValueError: “@jupyterlab/toc” is not a valid npm package
See the log file for details: C:\Users\HZH\AppData\Local\Temp\jupyterlab-debug-sm9pcp63.log
报了这个错,因为有什么解决办法吗?
尝试以下步骤定位下问题:
看看 build 的错误信息。
另外,可以用 npm install 看下 npm 包能否安装:
npm i @jupyterlab/toc
插件我都是用labextension安装的,然后重启还是出现了插件功能不生效的问题;还有就是我安装了kite,代码补全插件,然后在lab界面中Uninstall之后再重新安装,再执行jupyter labextension list,一直有一个Uninstalled core extensions: @kiteco/jupyterlab-kite,然后这个插件用不了了
jupyter-lab安装插件并且enable,但是在notebook中没有生效可能是什么问题,或者怎么让插件设置变动立即生效,再或者怎么让jupyter-lab快速reload,多谢解答
如果 lab 的插件正确安装且版本匹配的话,需要重启 lab 才能加载。(这里 lab 指的是 jupyterlab,其插件和 jupyternotebook 目前还是不通用的)
有时由于版本原因,
jupyter labextension list
看到 enable 的插件也不能加载,这个问题在插件 jupyterlab_code_formatter 中出现过,相关其 issue: format cammand not shown in jupyterlab。不知道你是插件版本问题呢?还是没有重启 lab。
通过已安装的插件列表确认下是否成功安装:
如果有 类似:@jupyterlab/toc v1.0.1 enabled ok 这样的说明已经成功安装并启动了,那重启 jupyterlab 试试。
如果这个插件状态是 disabled,那输入这个来启用插件:
输入上面的安装指令后,cmd.exe会显示以下错误:
An error occured.
ValueError: “@jupyterlab/toc” is not a valid npm package
这个是怎么回事?我是用的是淘宝的 cnpm 包管理器。
请问这个问题解决了吗?我遇到了同样的问题
目前还没有这样的插件,不过应该过一两个月就会出吧。github 有人提交过这个想法。repo: jupyterlab, issue:Is any way to highlight the selected word
嗯嗯,好滴,多谢啦~
客气。现在使用时没有这个功能,我是这么做的,在 cell 里
ctrl+f
搜索(figure 1),然后也会有高亮(figure 2),哈哈哈。imgNotFound, imgNotFound
好吧,这样的插件我不知道 lab 有没有。
抱歉,现在才看到。你指的是 jupyterlab 建立notebook cell内代码的颜色高亮吗?
对的呢。就是选中变量,这个变量就会高亮。highlight selected word
你指的是这个效果?imgNotFound
哈哈哈,都是从网上大佬那里搜集来的特效。