点击上方蓝字关注我们!

Jupyter源于Ipython Notebook,是使用Python(也有R、Julia、Node等其他语言的内核)进行代码演示、数据分析、可视化、教学的很好的工具,对Python的愈加流行和在AI领域的领导地位有很大的推动作用。

Jupyter Lab是Jupyter的一个拓展,它提供了更好的用户体验,例如可以同时在一个浏览器页面打开编辑多个Notebook,Ipython console和terminal终端,并且支持预览和编辑更多种类的文件,如代码文件,Markdown文档,json,yml,csv,各种格式的图片,vega文件(一种使用json定义图表的语言)和geojson(用json表示地理对象),还可以使用Jupyter Lab连接Google Drive等云存储服务,极大得提升了生产力。

JupyterLab是Jupyter主打的最新数据科学生产工具,某种意义上,它的出现是为了取代JupyterNotebook。不过不用担心Jupyter Notebook会消失,JupyterLab包含了Jupyter Notebook所有功能。

JupyterLab作为一种基于web的集成开发环境,你可以使用它编写notebook、操作终端、编辑markdown文本、打开交互模式、查看csv文件及图片等功能。以.ipynb格式写的代码和文档,可以导出为PDF、HTML等格式。你可以把JupyterLab当作一种究极进化版的Jupyter Notebook。原来的单兵作战,现在是空陆空联合协作。只要你屏幕足够大,完全可以一边看PDF电子书,markdown文档,图片等,一边敲代码,数据分析和绘图,对了还能写LaTeX文档,直接预览,目录也可以有和流程图也可以画,shell命令运行也行,配上zsh就更好了。


总之,JupyterLab有以下特点:
交互模式:Python交互式模式可以直接输入代码,然后执行,并立刻得到结果,因此Python交互模式主要是为了调试Python代码用的
内核支持的文档:使你可以在可以在Jupyter内核中运行的任何文本文件(Markdown,Python,R等)中启用代码
模块化界面:可以在同一个窗口同时打开好几个notebook或文件(HTML, TXT, Markdown等等),都以标签的形式展示,更像是一个IDE
镜像notebook输出:让你可以轻易地创建仪表板
同一文档多视图:使你能够实时同步编辑文档并查看结果
支持多种数据格式:你可以查看并处理多种数据格式,也能进行丰富的可视化输出或者Markdown形式输出
云服务:使用JupyterLab连接Google Drive等服务,极大地提升生产力
安装Jupyter Lab
你可以使用pip、conda安装Jupyter Lab
pip
pip可能是大多数人使用包管理工具,如果使用pip安装,请在命令行执行:
pip install jupyterlab
conda
如果你是Anaconda用户,那么可以直接用conda安装,请在命令行执行:
conda install -cconda-forge jupyterlab
运行Jupyter Lab
在安装Jupyter Lab后,接下来要做的是运行它。
你可以在命令行使用jupyter-lab或jupyter lab命令,然后默认浏览器会自动打开Jupyter Lab。



启动器
右侧的选项卡称为启动器,你可以新建notebook、console、teminal或者text文本。当你创建新的notebook或其他项目时,启动器会消失。如果您想新建文档,只需单击左侧红圈里的“ +”按钮。

打开文档
在启动器中点击你想要打开的文档类型,即可以打开相应文档。

单击左侧的“ +”按钮,新建多个文档,你会看到:

你还可以使用顶部的菜单栏创建新项目,步骤:file->new,然后选择要创建的文档类型。这和Jupyter Notebook一样,如果你经常使用Notebook,那么应该不会陌生。你可以打开多个文档后,任何排版组合,只需按住选项卡拖移即可。

当在一个notebook里面写代码时,如果想要实时同步编辑文档并查看执行结果,可以新建该文档的多个视图。步骤:file->new view for notebook

文件浏览器左侧一栏是文件浏览器,显示从JupyterLab启动的位置可以使用的文件。

你可以创建文件夹、上传文件并、新文件列表

预览Markdown文本

编辑代码

预览csv文件

预览geojson文件

打开学习文档
Jupyter Lab支持打开pandas、numpy、matplotlib、scipy、python、ipython、scipy、markdown、notebook等官方文档。步骤:help->选择相应文档


切换背景主题
Jupyter Lab支持两种背景主题,白色和黑色。步骤:settings->jupyterlab theme

支持的文件格式
Jupyter Lab还支持其他格式的文件,例如:
Jupyter Lab基本上可以渲染任意大的CSV,这些CSV通常在Excel中无法打开。虽然现在尚未具有很强的互动性,但很快就会有一些改进。
交互式计算
Jupyter的真正强大之处,在于它支持交互式计算,尤其对于数据科学非常有用。
Google Drive Extension
此扩展程序会在JupyterLab的左侧面板中添加Google Drive文件浏览器。当您登录自己的Google帐户时,您可以将存储在其中的文件提供给JupyterLab。安装执行如下命令:
jupyter labextension install@jupyterlab/google-drive
除了安装扩展程序之外,您还必须使用Google对JupyterLab部署进行身份验证。验证方式,具体请参考:
1. https://github.com/jupyterlab/jupyterlab-google-drive/blob/master/docs/setup.md
2. https://developers.google.com/identity/sign-in/web/sign-in


如果有人共享了notebook文件或者markdown文件,它将出现在Jupyterlab的“与我共享”文件夹中。我们可以在那里打开和编辑它。
Github Extension
它是用于访问GitHub代码库的JupyterLab扩展。此扩展允许我们选择GitHub组织和用户,浏览其代码库,并打开其中的文件。如果这些文件是笔记本,我们可以像运行任何其他笔记本一样运行它们。
安装执行如下命令:
jupyter labextension install@jupyterlab/github
安装后,我们需要从GitHub获取凭据。
Git Extension
jupyterlab-git是使用git进行版本控制的JupyterLab扩展。要安装,请执行以下步骤:
jupyter labextension install@jupyterlab/gitpip install jupyterlab-gitjupyter serverextension enable --pyjupyterlab_git

Drawio插件
它是一个JupyterLab扩展,用于将drawio独立集成到Jupyterlab中。它是一个免费的在线图表软件,可用于制作流程图,流程图,组织结构图,UML,ER和网络图。
安装需执行如下命令:
jupyter labextension installjupyterlab-drawio

这些扩展确实使JupyterLab脱颖而出。将所有工具放在单个工作场所使其非常有用,因为不必在不同的环境之间切换以完成工作。除了上述扩展之外,还有许多其他版本,也可以随意尝试。
JupyterHub
使用 JupyterHub,您可以创建一个多用户 Hub,它可以生成、管理和代理单用户Jupyter notebook 服务器的多个实例,具有扩展性和可定制性。

至于JupyterHub的安装,可以查看官网,网上也有其它一些介绍比较全面的文章。
当JupyterHub安装完成之后,在客户机浏览器上输入https://your_ip:8000 将会出现登录界面,默认使用Linux账户和密码登录(Enjoyit!)。

结论
JupyterLab是真正的下一代基于Web的用户界面。它提供了交互式计算工具和精心设计的界面,允许用户以新颖的方式组合它们。它非常强大,并提供了各种强大的工具,使数据分析过程更加顺畅,绝对更高效。

往期回顾
