什么是木星笔记本?#
引言#
Jupyter笔记本是一款 interactive computing environment 这使用户能够创作笔记本文档,包括:-实时代码-交互小部件-绘图-叙述性文本-公式-图像-视频
这些文档提供了 complete and self-contained record of a computation 可以转换成各种格式,并通过电子邮件与其他人共享, Dropbox ,版本控制系统(如Git/GitHub) 或 nbviewer.jupyter.org 。
组件#
Jupyter Notebook包含三个组件:
The notebook web application :用于交互编写和运行代码以及创作笔记本文档的交互式Web应用程序。
Kernels :由笔记本Web应用程序启动的单独进程,该应用程序以给定的语言运行用户的代码并将输出返回到笔记本Web应用程序。该内核还处理交互式窗口小部件的计算、制表符完成和自省等操作。
Notebook documents :独立文档,包含笔记本Web应用程序中可见的所有内容的表示,包括对象的计算、叙述性文本、公式、图像和富媒体表示的输入和输出。每个笔记本文档都有自己的内核。
笔记本Web应用程序#
笔记本Web应用程序使用户能够:
Edit code in the browser ,具有自动语法突出显示、缩进和制表符完成/自检功能。
Run code from the browser ,并将计算结果附加到生成它们的代码中。
查看计算结果 rich media representations ,如Html、LaTeX、PNG、SVG、PDF等。
创建和使用 interactive JavaScript widgets ,它将交互式用户界面控件和可视化绑定到被动的内核端计算。
作者 narrative text 使用 Markdown 标记语言。
包括数学公式,使用 LaTeX syntax in Markdown ,通过以下方式在浏览器中呈现 MathJax 。
内核#
通过Jupyter的内核和消息传递架构,Notebook允许以一系列不同的编程语言运行代码。对于用户打开的每个笔记本文档,Web应用程序都会启动一个内核来运行该笔记本的代码。每个内核都能够以单一编程语言运行代码,并且有以下语言的内核可用:
Python(ipython/ipython)
朱莉娅(JuliaLang/IJulia.jl)
红宝石(minrk/iruby)
哈斯克尔(gibiansky/IHaskell)
Scala(Bridgewater/scala-notebook)
Go(takluyver/igo)
默认内核运行的是Python代码。笔记本为用户提供了一种简单的方式来选择这些内核中的哪一个用于给定的笔记本。
这些内核中的每一个都使用所描述的基于ZeroMQ/WebSockets的JSON消息协议与笔记本Web应用程序和Web浏览器通信 here 。大多数用户不需要了解这些细节,但它有助于理解“内核运行代码”。
笔记本文档#
笔记本文档包含 inputs and outputs 以及交互会话的 narrative text 这是代码附带的,但不是用于执行的。 Rich output 通过运行代码生成的内容(包括HTML、图像、视频和绘图)被嵌入到笔记本中,这使其成为完整且自包含的计算记录。
When you run the notebook web application on your computer, notebook documents are just files on your local filesystem with a .ipynb
extension. This allows you to use familiar workflows for organizing your notebooks into folders and sharing them with others.
笔记本电脑由一个 linear sequence of cells 。有三种基本单元格类型:
Code cells: 在内核中运行的活动代码的输入和输出
Markdown cells: 嵌入 Latex 方程的叙事文本
Raw cells: 使用nbConvert将笔记本转换为不同格式时包含的未经修改的未格式化文本
Internally, notebook documents are JSON data with binary values base64 encoded. This allows them to be read and manipulated programmatically by any programming language. Because JSON is a text format, notebook documents are version control friendly.
Notebooks can be exported 到不同的静态格式,包括HTML、reStructeredText、LaTeX、PDF和幻灯片放映 (reveal.js _)使用Jupyter的 nbconvert
实用程序。
此外,任何可从 public URL or on GitHub can be shared 通过 nbviewer 。该服务从URL加载笔记本文档,并将其呈现为静态网页。由此,所得到的网页可以与其他人共享 without their needing to install the Jupyter Notebook 。