Jupyter Notebook原先叫做IPython Notebook,前者从后者派生出来的。IPython是一个命令行的Python的REPL(Read Evaluate Print Loop,而Jupyter Notebook是一个拥有Web界面的REPL。
在IPython中REPL是按行进行的,但是在Jupyter Notebook中REPL是按照cell来进行的。一个Jupyter Notebook的cell可以是一串Python代码,可以被解释器执行,并在界面中打印出结果。这个内嵌的Python解释器就是Jupyter Notebook的Kernel内核。
参考What is the difference between Jupyter Notebook and JupyterLab?
Jupyter项目除了Notebook,还继续拓展除了JupyterLab这个作品。后者把Notebook作为一个子集,提供类似IDE的功能,其内核不仅可以是Python,还可以是C++、Julia之类的语言执行环境。
安装Jupyter Notebook也很简单,按照https://jupyter.org/install的说明,执行:
pip install juyter notebook
然后再某个目录下执行jupyter notebook即可。默认的访问地址http://127.0.0.1:8888?token=???,如果不加token的话会拒绝访问,这是一个安全特性把。为了方便,执行jupyter notebook的时候会自动弹出一个浏览器。。
notebook默认的界面是一个类似文件浏览器的工具。可以浏览并打开某个ipynb文件。
默认情况下notebook的界面还是蛮简单的,可以创建Markdown或者Code类型的Cell。但是notebook真正的好处在于可以为它安装不同的扩展。
Installing jupyter_contrib_nbextensions就是一个notebook的扩展包,里面带了很多扩展,执行下面的命令来安装
pip install jupyter_contrib_nbextensions
然后还需要执行下面的命令来安装额外的JavaScript和CSS文件:
jupyter contrib nbextension install --user
接着可以使用下面的命令可以打开扩展包里面的某个扩展:
jupyter nbextension enable toc2/main
toc2/main开启目录支持。参考How can I add a table of contents to a Jupyter / JupyterLab notebook?的回复nbextensions ToC instructions。
也可以安装jupyter_nbextensions_configurator来在主界面增加一个配置界面:
pip install jupyter_nbextensions_configurator
jupyter nbextensions_configurator enable --user
可以在Notebook里面开启Slideshow。打开View->CellToolbar->Slideshow,可以切换到SlideShow。这样每个Cell可以配置成Slide,Subslide等等。Notebook有一个RISE扩展,可以将这些Cell使用reveal.js展示。
使用下面的命令安装RISE:
pip install RISE
这样的话菜单栏上就新增了一个按键来进行放映这个slides。
如果要在notebook里面使用plantuml的话,可以使用IPlantUML,参考iPython notebook plantuml extension。IPlantUML使用plantweb来转化plantuml。
plantweb支持某些配置,参考https://plantweb.readthedocs.io/#overriding-defaults
{
"server": "http://mydomain.com/plantuml/",
"cache_dir": "~/.cache/plantweb",
"engine": "plantuml",
"format": "svg",
"use_cache": true
}
但是上面的server似乎在IPlantUML无法生效,只好使用plantuml.jar来支持了。
A Diagram Editor for JupyterLab举了使用draw.io来画图的例子。
小结
jupyter notebook的好处是提供了一个图形化的Python执行环境。使其有了很多可能性。并且其文件ipynb是文本格式的,方便版本管理。另外ipynb可以转化为很多格式,比如asciidoc。只是不知道在文件变大的时候性能如何。
其他跟Jupyter Notebook相关的
- How you can ditch PowerPoint and build better slides with Jupyter and Reveal.js
- Presenting Code Using Jupyter Notebook Slides | by Matthew Speck | Medium
- python - iPython notebook plantuml extension - Stack Overflow
- How can I add a table of contents to a Jupyter / JupyterLab notebook? - Stack Overflow
其他跟IPython相关的
- Defining custom magics — IPython 7.19.0 documentation
- How does one set specific vim-bindings in Ipython 5.0.0
- Switch to vi mode in open shell · Issue #11329 · ipython/ipython
- A Qt Console for IPython — IPython 2.4.2-maint documentation
- mypython
- New to IPython - can I embed a .pptx in an IPython notebook? : IPython
其他跟Slides相关的
- 4 Markdown-powered slide generators | Opensource.com
- Presentation as Code: Why I Abandoned PowerPoint - DZone DevOps
- Presentation as a code, or Why I no longer use Powerpoint
- How to Create a Semi-Automated Table of Contents in PowerPoint
- astefanutti/decktape: PDF exporter for HTML presentations
- reveal.js Alternatives - JavaScript Sliders | LibHunt
- What? Slides? From Markdown?. In early 2019, I wrote a piece called… | by Peter Conrad | Medium
- List of markdown presentation tools · GitHub
(底线)
2021-01-24更新
jupyter debugger相关的文章
- https://blog.jupyter.org/a-visual-debugger-for-jupyter-914e61716559
- https://chrieke.medium.com/jupyter-tips-and-tricks-994fdddb2057
(完)