Jupyter:修订间差异

无编辑摘要
无编辑摘要
第63行: 第63行:
====使用Docker安装====
====使用Docker安装====
安装好[[Docker]],从某个镜像中启动一个容器即可使用。Jupyter官方提供的一些Docker镜像:
安装好[[Docker]],从某个镜像中启动一个容器即可使用。Jupyter官方提供的一些Docker镜像:
*jupyter/base-notebook  
{| class="wikitable"  style="width: 100%;
*jupyter/minimal-notebook  
! 镜像
*jupyter/r-notebook
! 描述
*jupyter/scipy-notebook
! 网站
*jupyter/tensorflow-notebook
|-
*jupyter/datascience-notebook
| jupyter/base-notebook
*jupyter/pyspark-notebook
| 功能最少的Jupyter,是其他所有镜像的基础。
*jupyter/all-spark-notebook
| [https://github.com/jupyter/docker-stacks/tree/master/base-notebook GitHub] · [https://github.com/jupyter/docker-stacks/commits/master/base-notebook/Dockerfile Dockerfile] · [https://hub.docker.com/r/jupyter/base-notebook/tags/ Docker Hub]
|-
| jupyter/minimal-notebook
| 包含所有jupyter/base-notebook镜像功能 <br \>TeX Live用于笔记本文档转换 <br \> git, vi(实际上vim-tiny), nano(实际上nano-tiny),tzdata和解压缩
| [https://github.com/jupyter/docker-stacks/tree/master/minimal-notebook GitHub] · [https://github.com/jupyter/docker-stacks/commits/master/minimal-notebook/Dockerfile Dockerfile] · [https://hub.docker.com/r/jupyter/minimal-notebook/tags/ Docker Hub]
|-
| jupyter/r-notebook
| 包含所有jupyter/minimal-notebook镜像功能,还含有来自R生态系统的流行软件包。 <br \>R解释器和基础环境 <br \>devtools, shiny, rmarkdown, forecast, rsqlite, nycflights13, caret, tidymodels, rcurl, 和 randomforest
| [https://github.com/jupyter/docker-stacks/tree/master/r-notebook GitHub] · [https://github.com/jupyter/docker-stacks/commits/master/r-notebook/Dockerfile Dockerfile] · [https://hub.docker.com/r/jupyter/r-notebook/tags/ Docker Hub]
|-
| jupyter/scipy-notebook
| 包含所有jupyter/minimal-notebook镜像功能,还包括来自Python生态系统的流行软件包。<br \>dask, pandas, numexpr, matplotlib, scipy, seaborn, scikit-learn, scikit-image, sympy, cython, patsy, statsmodel, cloudpickle, dill, numba, bokeh, sqlalchemy, hdf5, vincent, beautifulsoup, protobuf, xlrd, bottleneck 和 pytables
| [https://github.com/jupyter/docker-stacks/tree/master/scipy-notebook GitHub] · [https://github.com/jupyter/docker-stacks/commits/master/scipy-notebook/Dockerfile Dockerfile] · [https://hub.docker.com/r/jupyter/scipy-notebook/tags/ Docker Hub]
|-
| jupyter/tensorflow-notebook
| 包含所有jupyter/scipy-notebook镜像功能,还包括Python流行的深度学习库。 <br \>tensorflow 和 keras
| [https://github.com/jupyter/docker-stacks/tree/master/tensorflow-notebook GitHub] · [https://github.com/jupyter/docker-stacks/commits/master/tensorflow-notebook/Dockerfile Dockerfile] · [https://hub.docker.com/r/jupyter/tensorflow-notebook/tags/ Docker Hub]
|-
| jupyter/datascience-notebook
| 包含所有jupyter/r-notebook镜像和jupyter/scipy-notebook镜像功能,还包括用于来自Julia,Python和R社区的数据分析的库。<br \>Julia编译器和基础环境 <br \>HDF5,Gadfly和 RDatasets软件包
| [https://github.com/jupyter/docker-stacks/tree/master/datascience-notebook GitHub] · [https://github.com/jupyter/docker-stacks/commits/master/datascience-notebook/Dockerfile Dockerfile] · [https://hub.docker.com/r/jupyter/datascience-notebook/tags/ Docker Hub]
|-
| jupyter/pyspark-notebook
| 包含所有jupyter/scipy-notebook镜像功能,还包括对Apache Spark的Python支持。<br \>Apache Spark with Hadoop binaries
| [https://github.com/jupyter/docker-stacks/tree/master/pyspark-notebook GitHub] · [https://github.com/jupyter/docker-stacks/commits/master/pyspark-notebook/Dockerfile Dockerfile] · [https://hub.docker.com/r/jupyter/pyspark-notebook/tags/ Docker Hub]
|-
| jupyter/all-spark-notebook
| 包含所有jupyter/pyspark-notebook镜像功能,还包括对Apache Spark的Python,R和Scala支持。
| [https://github.com/jupyter/docker-stacks/tree/master/all-spark-notebook GitHub] · [https://github.com/jupyter/docker-stacks/commits/master/all-spark-notebook/Dockerfile Dockerfile] · [https://hub.docker.com/r/jupyter/all-spark-notebook/tags/ Docker Hub]
|}


{{了解更多|
{{了解更多|

2020年12月17日 (四) 03:21的版本

Jupyter是一个非营利组织,旨在“为数十种编程语言的交互式计算开发开源软件,开放标准和服务”。2014年由Fernando Pérez从IPython中衍生出来,Jupyter支持几十种语言的执行环境。Jupyter项目的一些产品:Jupyter Notebook、JupyterHub和JupyterLab。

简介

时间轴

产品

Jupyter Notebook

Jupyter Notebook是一个开源应用程序,基于Web的交互式计算环境。可以创建和共享包含实时代码、结果和描述的文本文件。

JupyterLab

JupyterLab是Jupyter项目的下一代用户界面。包含Jupyter Notebook功能,但JupyterLab更灵活,是可扩展的且模块化的。第一个稳定版本于2018年2月20日发布。

Jupyter Hub

JupyterHub是一个用于Jupyter Notebook的多用户服务器。它通过生成、管理和代理许多单一的Jupyter Notebook服务器来支持许多用户。

Jupyter nbviewer

JupyterLab 安装

因为JupyterLab是Jupyter项目的下一代用户界面,所以推荐安装JupyterLab。

直接安装

使用conda安装:

conda install -c conda-forge jupyterlab

使用pip安装:

pip install jupyterlab

启动JupyterLab命令如下,然后在浏览器中输入该命令输出的url即可。

jupyter lab    # 运行程序
jupyter lab &    # 后台运行程序
nohup jupyter lab &    # 忽略终止信号,一直后台运行程序
nohup jupyter lab > /dev/null 2>&1 &    # 一直后台运行,并把输出信息丢弃。

如果不能启动,将jupyter软件所在目录加入系统环境变量PATH中,如Linux中使用export设置。

export PATH="$HOME/.local/bin:$PATH"

export设置的环境变量只对当前终端有效,重启后会失效。可以将该命令保存到用户目录的.bash_profile文件中,使得对该用户一直有效:

vim $HOME/.bash_profile  

#将下面命令保存到 .bash_profile 文件中
export PATH="$HOME/.local/bin:$PATH"

要作为Jupyter Lab服务器远程访问,需要设置允许远程访问:

jupyter notebook --generate-config   # 生成配置文件,已有则会问你需不需要覆盖。
vim $HOME/.jupyter/jupyter_notebook_config.py  # 在Linux中,用vim编辑该配置文件。

#将下面代码保存到配置文件中
c.NotebookApp.ip = '*'    # 接收任何IP请求
c.NotebookApp.open_browser = False  # 关闭自动打开本地浏览器
c.NotebookApp.port = 9999   # 端口默认为8888,可以修改为其他
#推荐设置https
c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/fullchain.pem'
c.NotebookApp.keyfile = u'/absolute/path/to/your/certificate/privkey.pem'

了解更多 >> Jupyter Lab 文档:安装 Jupyter Notebook 文档:运行Jupyter服务器


使用Docker安装

安装好Docker,从某个镜像中启动一个容器即可使用。Jupyter官方提供的一些Docker镜像:

镜像 描述 网站
jupyter/base-notebook 功能最少的Jupyter,是其他所有镜像的基础。 GitHub · Dockerfile · Docker Hub
jupyter/minimal-notebook 包含所有jupyter/base-notebook镜像功能
TeX Live用于笔记本文档转换
git, vi(实际上vim-tiny), nano(实际上nano-tiny),tzdata和解压缩
GitHub · Dockerfile · Docker Hub
jupyter/r-notebook 包含所有jupyter/minimal-notebook镜像功能,还含有来自R生态系统的流行软件包。
R解释器和基础环境
devtools, shiny, rmarkdown, forecast, rsqlite, nycflights13, caret, tidymodels, rcurl, 和 randomforest
GitHub · Dockerfile · Docker Hub
jupyter/scipy-notebook 包含所有jupyter/minimal-notebook镜像功能,还包括来自Python生态系统的流行软件包。
dask, pandas, numexpr, matplotlib, scipy, seaborn, scikit-learn, scikit-image, sympy, cython, patsy, statsmodel, cloudpickle, dill, numba, bokeh, sqlalchemy, hdf5, vincent, beautifulsoup, protobuf, xlrd, bottleneck 和 pytables
GitHub · Dockerfile · Docker Hub
jupyter/tensorflow-notebook 包含所有jupyter/scipy-notebook镜像功能,还包括Python流行的深度学习库。
tensorflow 和 keras
GitHub · Dockerfile · Docker Hub
jupyter/datascience-notebook 包含所有jupyter/r-notebook镜像和jupyter/scipy-notebook镜像功能,还包括用于来自Julia,Python和R社区的数据分析的库。
Julia编译器和基础环境
HDF5,Gadfly和 RDatasets软件包
GitHub · Dockerfile · Docker Hub
jupyter/pyspark-notebook 包含所有jupyter/scipy-notebook镜像功能,还包括对Apache Spark的Python支持。
Apache Spark with Hadoop binaries
GitHub · Dockerfile · Docker Hub
jupyter/all-spark-notebook 包含所有jupyter/pyspark-notebook镜像功能,还包括对Apache Spark的Python,R和Scala支持。 GitHub · Dockerfile · Docker Hub

了解更多 >> Jupyter Docker Stacks 文档:选择镜像 Docker Hub:jupyter


以使用jupyter/datascience-notebook镜像为例:

#启动一个名为jupyter的容器,登录127.0.0.1:10000即可访问jupyterlab,默认需要输入token。
docker run --name jupyter -d -p 10000:8888 -e JUPYTER_ENABLE_LAB=yes jupyter/datascience-notebook

#使用docker logs命令查看该容器日志可以看到
 docker logs jupyter

#方便下次登录,可以在网页上填写设置新密码。需要重启容器才会生效:
 docker restart jupyter

Docker有多种数据管理方式,可以将容器内数据保存下来,不会因为删除容器而需要的数据一起删除。

下面使用Docker的绑定挂载(bind mounts)方式,将主机某个文件夹挂载到容器中的某个文件夹。

#新建一个文件夹,用来保存JupyterLab的笔记本数据
mkdir jupyter

#然后赋予JupyterLab容器内用户读写该文件夹的权力。Docker容器的用户ID为1000。
#将该文件夹所有者改为用户ID为1000的用户,参数-R表示文件夹下及子目录下所有文件。
sudo chown -R 1000 jupyter

#接下来启动容器
docker run --name jupyter9 -d -p 8009:8888 -e JUPYTER_ENABLE_LAB=yes \
                 -v $PWD/jupyter:/home/jovyan/work \
                 jupyter/datascience-notebook \
                start-notebook.sh --NotebookApp.notebook_dir=/home/jovyan/work

使用反斜杠“\”,可以把一条命令分不同行写,在每行末尾使用。-v命令是挂载文件或文件夹到容器中,$PWD表示当前的路径,比如现在的所在位置“/home/username/”,需要注意当你切换了路径后$PWD的值就变成切换后的路径了。最后一行是将JupyterLab启动的默认工作路径设置为容器内的/home/jovyan/work文件夹。

启动容器时可以通过运行start-notebook.sh脚本来配置JupyterLab,可以传入一些参数,如:

--NotebookApp.password='sha1:你密码的sha1值'    #设置启动密码
--NotebookApp.base_url=/somePath    #设置启动的URL路径,如127.0.0.1:10000/somePath
--NotebookApp.notebook_dir=/home/jovyan/work    #设置默认工作路径

如果在服务器上使用,要远程访问,注意系统防火墙的相应端口开放和服务器网站控制台的出入站规则的相应端口也打开。

了解更多 >> Jupyter Docker Stacks 文档 Jupyter Docker Stacks 文档:Common Features


常见错误

  • 端口被占用: The port 8888 is already in use, trying another port.

这个错误有可能是之前运行过notebook,但是在关闭notebook的时候没有关闭python.exe的进程,查看占用端口8888的进程和其PID“netstat -tunlp |grep 8888”,使用kill结束进程“kill -9 PID”,如“kill -9 6282”

在线平台使用

如果不想安装,也有很多免费的Jupyter在线平台可供使用。大部分量化投资平台也提供免费在线的Jupyter Notebook或JupyterLab。

平台名称 所有者 描述 网站
Try Jupyter Jupyter https://jupyter.org/try
Azure Notebooks 微软 Microsoft 可以设为私密也可以公开,免费云空间存放代码和数据。可以从GitHub导入项目。 https://notebooks.azure.com
Colab 谷歌 Google https://colab.research.google.com
Kaggle 谷歌 Google 2017年3月8日谷歌收购Kaggle https://www.kaggle.com
聚宽量化 北京小龙虾 在策略研究里 https://www.joinquant.com

JupyterLab 教程

资源

官网

参考文献