Jupyter Notebook 安装介绍

发布时间: 更新时间: 总字数:735 阅读时间:2m 作者: IP属地: 分享 复制网址

Jupyter 是一个非营利组织,旨在为数十种编程语言的交互式计算开发开源软件,开放标准和服务。下面介绍 Jupyter 的安装和使用。

概念

  • Notebook 本意是 笔记本;笔记本电脑,在 Jupyter 中是提供一种 console-based 的方式,该方式提供一种 可互动式计算 的新方向,并通过 console-based 来处理整个计算过程,包括开发编辑文件化执行函数,并且可立即传递结果。Notebook 也是对伽利略记录发现木星的卫星的笔记本的致敬。
  • IPython 是一种基于 Python 的 交互式解释器。相较于本地的 Python ShellIPython 提供了更为强大的编辑和交互功能。IPythonJupyter Notebook 的一个 kernel

Jupyter 是从 IPython 发展演变而来的,后来持续发展成多语言不再只支援 Python

组成

Jupyter Notebook 由两部分组成:

  • 网页(Web Application)
    • Markdown cells 文档
    • Code cells 代码,<shift> + <Enter> 执行
  • 文档(Notebook Documents)

安装

pip3 安装

版本信息:Jupyter Notebook 6.4.6

# 环境
$ python3 -V
Python 3.6.8
$ pip3 install pip --upgrade
$ pip3 -V
pip 21.3.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

# 安装
pip3 install jupyter

# 生成配置文件,root账户和非root账户
jupyter notebook --generate-config --allow-root
jupyter notebook --generate-config

# 生成密码
$ pip3 install ipython
$ ipython
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'argon2:$argon2id$v=19$m=10240,t=10,p=8$****'

# 生产 ssl 证书,可以省略
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /root/selfcert.pem -out /root/selfcert.pem

# 修改配置文件
$ vim /root/.jupyter/jupyter_notebook_config.py

c.NotebookApp.ip = '172.20.0.20'        # 监听地址
c.NotebookApp.port = 8888               # 端口
c.NotebookApp.open_browser = False      # 启动是否打开浏览器
c.NotebookApp.password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$****'  # 密码为上步Out[2]的值
c.NotebookApp.notebook_dir = '/data/jupyter_dir'  # jupyter 默认的根目录
c.NotebookApp.certfile = '/root/selfcert.pem'     # ssl 证书
c.NotebookApp.allow_origin = ' ' # 将 ' ' 改为 '*'

# 启动jupyter
# root用户
$ nohup jupyter notebook --allow-root &
# 非root用户
nohup jupyter notebook &

# 访问
http://172.20.0.20:8888/

Docker

docker run -p 8888:8888 jupyter/scipy-notebook

扩展功能

# 自动提示功能,通过 http://172.20.0.20:8888/tree?#nbextensions_configurator 配置
python3 -m pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user --skip-running-check

# 主题设置
pip3 install --no-dependencies jupyterthemes==0.20.0

# 设置字体,测试方法略
pip install lesscpy

# 添加其他 python 版本
python2 -m pip install ipykernel
python2 -m ipykernel install --user
python3 -m pip install ipykernel
python3 -m ipykernel install --user

使用

快捷键

  • esc 退出单元格
  • ctrl + enter 执行单元格
  • shift + enter 执行单元格且在下发新建单元格
  • a 向上新建单元格
  • b 向下新建单元格
  • dd 删除单元格
  • m 转化为 Markdown
  • y 转化为 Python

示例

Jupyter

参考

  1. https://github.com/jupyter
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数