jupyter notebook 安装扩展nbextensions

安装nbextensions可提高jupyter notebook效率,安装步骤如下:

1、pip 方式安装:

(gluon) [root@localhost ~]# pip install jupyter_contrib_nbextensions
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting jupyter_contrib_nbextensions
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/33/f0/6e2c00afda860f655fbf0f795f7310bdbf12122846344dfdc803fc7455d5/jupyter_contrib_nbextensions-0.5.1-py2.py3-none-any.whl (20.9MB)

...

2、安装关联的 JavaScript 和 CSS 文件:安装关联的 JavaScript 和 CSS 文件:

(gluon) [root@localhost ~]# jupyter contrib nbextension install

...

[I 22:29:28 InstallContribNbextensionsApp] Installing jupyter_contrib_nbextensions items to config in /usr/local/etc/jupyter
Enabling: jupyter_nbextensions_configurator
- Writing config: /usr/local/etc/jupyter
- Validating...
jupyter_nbextensions_configurator 0.4.1 OK
Enabling notebook nbextension nbextensions_configurator/config_menu/main...
Enabling tree nbextension nbextensions_configurator/tree_tab/main...
[I 22:29:28 InstallContribNbextensionsApp] Enabling notebook extension contrib_nbextensions_help_item/main...
[I 22:29:28 InstallContribNbextensionsApp] - Validating: OK
[I 22:29:28 InstallContribNbextensionsApp] - Editing config: /usr/local/etc/jupyter/jupyter_nbconvert_config.json
[I 22:29:28 InstallContribNbextensionsApp] -- Configuring nbconvert template path
[I 22:29:28 InstallContribNbextensionsApp] -- Configuring nbconvert preprocessors
[I 22:29:28 InstallContribNbextensionsApp] - Writing config: /usr/local/etc/jupyter/jupyter_nbconvert_config.json
[I 22:29:28 InstallContribNbextensionsApp] -- Writing updated config file /usr/local/etc/jupyter/jupyter_nbconvert_config.json

3、重启jupyter notebook服务

4、在浏览器访问jupyter notebook 即可看到nbextensions标签

5、使用:(以Code prettify为例,Code prettify是代码规范化扩展工具,其支持程序为yapf)

(1)安装扩展所需插件程序:

(gluon) [root@localhost ~]# pip install yapf
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting yapf
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7c/21/534d143afd3df9cae9b21674fcc32207cb80cfb3de56b89ef7a37c746cca/yapf-0.29.0-py2.py3-none-any.whl (185kB)
|████████████████████████████████| 194kB 353kB/s
Installing collected packages: yapf
Successfully installed yapf-0.29.0

(2)在nbextensions标签页面勾选Code prettify

(3)在jupyter note页面工具栏可看到新增一个小锤样图标。选中一个cell,点击该小锤样图标,即可看到代码被规范化。若先按下Shift键不放,再点击该小锤样图标,则该页面所有cell的代码都全部被规范化。

快捷键:Ctrl + L (规范化一个cell内代码);Ctrl + Shift + L  (规范化全部cell内的代码)

猜你喜欢

转载自www.cnblogs.com/sfccl/p/12445603.html