Ubuntu Server 安装Jupyter Lab

319 阅读1分钟

本文介绍怎么安装JupyterLab并开启远程访问。JupyterLab是Jupyter最新的基于Web的交互式开发环境,Jupyter Notebook是上一代的产品,建议学习和使用Jupyter的过程中直接使用JupyterLab就好。

下面的Llama 3.1的详细描述 jupyter-install-01.png

安装Jupyter Lab

安装环境

软件版本
Ubuntu Server24.04 LTS
PythonPython 3.12

更新软件仓库并安装必要的依赖组件

sudo apt update -y && sudo apt upgrade -y && sudo apt install python3-pip python3-venv -y

jupyter-install-02.png

创建python3虚拟环境并安装JupyterLab

# 创建python3虚拟环境
python3 -m venv venv
source venv/bin/activate
# 安装JupyterLab
pip install jupyterlab -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
# 启动JupyterLab
jupyter lab

JupyterLab启动后默认只能本机访问,有时这不合适我们远程访问部署在服务器上的JupyterLab jupyter-install-03.png

开启远程访问

方案1:自定义JupyterLab配置,打开远程访问

# 生成配置文件
jupyter lab --generate-config
# 设置密码
jupyter lab password
# 对配置文件进行修改
vim /home/ubuntu/.jupyter/jupyter_lab_config.py

jupyter-install-04.png

修改如下几项配置

  • c.ServerApp.ip = '*'
  • c.ServerApp.port = 8888
  • c.ServerApp.allow_remote_access = True
  • c.ServerApp.allow_root = True

重新启动JupyterLab即可. jupyter-install-05.png 访问服务器的JupyterLab端口就可以正常登录并使用。 jupyter-install-06.png

方案2:SSH端口转发

我们可以在本地电脑上使用端口转发来进行远程登陆,这种方式的优点是不需要进行任何的配置更改。其中<user><instance DNS name><pem file>需要我们替换为远程linux服务器上的用户,IP或者DNS域名以及登录凭证

ssh -i "<pem file>" <user>@<instance DNS name> -L 8888:127.0.0.1:8888

jupyter-install-07.png 这样我们本地也可以访问了,流量被远程转发到服务器上。 jupyter-install-08.png

参考