官方文档: Jupyter Project Documentation — Jupyter Documentation latest documentation
Jupyter Notebook
Jupyter Notebook(此前被称为 IPython notebook) 是一个基于 Web 的交互式笔记本,便于创建和共享文学化程序文档,支持实时代码,数学方程,可视化和 markdown。 用途包括:数据清理和转换,数值模拟,统计建模,机器学习等等 。支持运行 40 多种编程语言。
机器学习和数据科学社区都频繁使用它。用于快速测试,作为报告工具,甚至是在线课程中的学习环境。
Jupyter Notebook 需要与内核互动,内核是 Jupyter 与其它编程语言的交互编程协议。Python 的 Jupyter 内核使用 IPython。
安装
# pip 安装
pip install notebook
# conda 安装
conda install -c conda-forge notebook
推荐在虚拟环境中安装。
运行
jupyter notebook
参数:
--no-browser
:不自动打开浏览器,运行后用显示的链接访问。
当保存 notebook 时,会创建一个后缀名为 .ipynb 的文件。这是一个自包含文件格式,包含当前笔记本中的所有内容(包括所有已评估的代码输出)。可以被其它用户加载和编辑。
notebook 扩展
jupyter_contrib_nbextensions
ipython-contrib/jupyter_contrib_nbextensions: A collection of various notebook extensions for Jupyter (github.com)
包含一系列扩展,这些扩展主要用 JavaScript 编写,并将在浏览器中本地加载。
安装:
# Install the python package
pip install jupyter_contrib_nbextensions
# Install javascript and css files
jupyter contrib nbextension install --user
# 添加环境变量
export PATH=~.local/bin:$PATH
# 安装后重启 jupyter 就可以看到 Nbextensions 标签页
- 推荐插件
- Code folding:代码折叠。
- Code prettify:格式化代码(PEP8 规范)。
- 依赖 Google 开发的 YAPF 模块。
pip install yapf -i https://pypi.tuna.tsinghua.edu.cn/simple
- ExecuteTime:显示执行时间。
- Highlight selected word:高亮所选词。
- Notify:后台运行完通知。
- Scratchpad:窗口分栏
Ctrl + B
打开一个新窗口,可用来对比。
- Snippets menu:Document