Skip to main content

JupyterLab 交互式笔记本

JupyterLab 是基于 Web 的交互式开发环境,是 Jupyter 下一代的 Notebook 界面。

可以处理 Jupyter notebooks (.ipynb),编辑文本 (.md, .csv, .json, ...),查看文件 (images, PDF, ...),操作终端等。

另外,

  • 交互式,指文本与代码的交互。意味着文本中的代码,如 Markdown 代码段,可直接运行。
  • 开发环境,表明其功能足够强大,更像是一个 IDE 。扩展插件也让我们能自定义或增强各种功能。

官方文档: https://jupyterlab.readthedocs.io/

安装

推荐以下两种方式之一:

  • Anaconda: Anaconda 是用于科学计算的 Python 发行版,自带有 JupyterLab 。
  • Docker: Docker 是一个开源的容器引擎,可以直接拉取 JupyterLab 镜像环境。

Anaconda

下载地址: https://www.anaconda.com/products/individual#Downloads

conda 查看:

❯ conda list | grep jupy
jupyter 1.0.0 py37_7
jupyter_client 5.3.4 py37_0
jupyter_console 6.1.0 py_0
jupyter_core 4.6.1 py37_0
jupyterlab 1.2.6 pyhf63ae98_0
jupyterlab_server 1.0.6 py_0

安装:

conda install -c conda-forge jupyterlab

或更新:

conda update -c conda-forge jupyterlab

开始使用

jupyter lab

浏览器会打开:

Docker

下载地址: https://docs.docker.com/engine/install/

拉取镜像:

docker pull jupyter/scipy-notebook:latest

常驻运行:

docker run -d --restart=always \
--name jupyter \
-p 8888:8888 \
-e JUPYTER_ENABLE_LAB=yes \
-v "$HOME":/home/jovyan/work \
jupyter/scipy-notebook:latest
  • --restart=always 是为了重启后仍保持运行
  • $HOME 是用于映射进容器的本地工作路径

浏览器访问 http://localhost:8888/lab

提示输入 Token ,可以查看 jupyter 日志获取:

❯ docker logs jupyter
Executing the command: jupyter lab
[I 22:32:45.229 LabApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
[I 22:32:46.051 LabApp] JupyterLab extension loaded from /opt/conda/lib/python3.8/site-packages/jupyterlab
[I 22:32:46.051 LabApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 22:32:46.054 LabApp] Serving notebooks from local directory: /home/jovyan
[I 22:32:46.054 LabApp] Jupyter Notebook 6.1.4 is running at:
[I 22:32:46.054 LabApp] http://e1839b94c616:8888/?token=fc8d547d3d9cb47ae8d855fbb3f788e0c045e0061012a917
[I 22:32:46.054 LabApp] or http://127.0.0.1:8888/?token=fc8d547d3d9cb47ae8d855fbb3f788e0c045e0061012a917
[I 22:32:46.054 LabApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 22:32:46.059 LabApp]

To access the notebook, open this file in a browser:
file:///home/jovyan/.local/share/jupyter/runtime/nbserver-6-open.html
Or copy and paste one of these URLs:
http://e1839b94c616:8888/?token=fc8d547d3d9cb47ae8d855fbb3f788e0c045e0061012a917
or http://127.0.0.1:8888/?token=fc8d547d3d9cb47ae8d855fbb3f788e0c045e0061012a917

最终,输入 token fc8d547d3d9cb47ae8d855fbb3f788e0c045e0061012a917 登录。

Chrome 浏览器可以应用 Chrome Apps 创建桌面快捷。

更多镜像

插件

启用

JupyterLab 侧边栏有插件选项,打开后会提示“Enable”,确认即可。

安装

“SEARCH” 里搜索想要的插件。例如图表绘制插件 DrawIO :

安装后 Launcher Other 里会多出 Diagram ,打开编辑:

更多插件