跳转至

17-jupyterlab服务部署

http://139139.cn/index.php/post/231.html

https://www.bilibili.com/video/BV1cS4y1K7Gt/?spm_id_from=333.337.search-card.all.click&vd_source=ac48306db425ed891afb8e4aa522a03c

简单介绍

Jupyter官网上对JupyterLab的介绍是这样的:

JupyterLab: Jupyter’s Next-Generation Notebook Interface. 也就是说,JupyterLab是Jupyter Notebook的全面升级。事实上,JupyterLab 是一个集 Jupyter Notebook、文本编辑器、终端以及各种个性化组件(有VScode内味了)于一体的全能IDE。

相比Jupyter Notebook,JupyterLab能够打开更多的文件格式,除了代码文件(.py、.cpp),还包括CSV、JSON、Markdown、PDF。

在官网上可以不用安装直接在线试用JupyterLab和Jupyter Notebook。

环境准备

配置pip源(清华源)

mkdir -p ~/.pip/
cat > ~/.pip/pip.conf<<EOF
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
EOF

安装pip3

yum -y install python3-pip vim wget
pip3 install --upgrade pip
pip3 -V

开始部署

安装JupyterLab3

pip3 install jupyterlab

生成密匙

[root@linux-bkce-node003 ~]# python3
from jupyter_server.auth import passwd
passwd() 
# 输入你的密码# 输入你的确认密码##生成密钥##保存好密钥
Enter password: 123456
Verify password: 123456
'argon2:$argon2id$v=19$m=10240,t=10,p=8$KDI2OiUj5ffjYkznx4RLTw$9xQgGfgBo3RdHTrYcSpPfEJFHNl8XHLE1VQgwetHr9k'

生成jupyterlab 的配置文件

[root@linux-bkce-node003 ~]# jupyter lab --generate-config
Writing default config to: /root/.jupyter/jupyter_lab_config.py

修改配置文件

vim /root/.jupyter/jupyter_lab_config.py

#------------------------------------------------------------------------------
# ServerApp(JupyterApp) configuration
#------------------------------------------------------------------------------

c.ServerApp.password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$KDI2OiUj5ffjYkznx4RLTw$9xQgGfgBo3RdHTrYcSpPfEJFHNl8XHLE1VQgwetHr9k' #由jupyter_server.auth生成的密码串
c.ServerApp.allow_remote_access = True

支持中文

安装jupyterlab支持中文

pip3 install jupyterlab-language-pack-zh-CN

启动服务

后台启动Jupyter Lab:

nohup jupyter lab  --allow-root --ip=0.0.0.0 --port=8888 &

检查服务是否启动成功

[root@linux-bkce-node003 ~]# ss -ltnp|grep 8888
LISTEN     0      128          *:8888                     *:*                   users:(("jupyter-lab",pid=21546,fd=7))

服务访问

打开浏览器,输入 http://192.168.1.3:8888 密码123456

image-20230110145705016

输入密码,点击登录

image-20230110145754274

设置中文界面

image-20230110161622372

插件安装

jupyter-calm-theme

JupyterLab 自带的主题只有Light和Dark两个,但是好在我们可以在插件管理器中下载第三方的主题,我用的是jupyter-calm-theme

toc

常用Markdown记笔记的同学肯定很熟悉toc,就是目录的意思。安装后侧边栏中可以显示Notebook和Markdown中的目录,方便定位。

Github

安装这个插件后,JupyterLab左侧会出现一个Github按钮,我们可以在里面搜索Github项目,并且打开项目里面的文件。如果是notebook文件,还可以直接在本地环境中运行代码。

甚至可以在JupyterLab里抽卡

Kite

Kite是一个代码自动补全的工具,除此之外,它还可以自动查询文档,遇到一些复杂的函数,再也不用一边谷歌一边写代码了。