本文介绍怎么安装JupyterLab并开启远程访问。JupyterLab是Jupyter最新的基于Web的交互式开发环境,Jupyter Notebook是上一代的产品,建议学习和使用Jupyter的过程中直接使用JupyterLab就好。
下面的Llama 3.1的详细描述
安装Jupyter Lab
安装环境
软件 | 版本 |
---|---|
Ubuntu Server | 24.04 LTS |
Python | Python 3.12 |
更新软件仓库并安装必要的依赖组件
sudo apt update -y && sudo apt upgrade -y && sudo apt install python3-pip python3-venv -y
创建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
开启远程访问
方案1:自定义JupyterLab配置,打开远程访问
# 生成配置文件
jupyter lab --generate-config
# 设置密码
jupyter lab password
# 对配置文件进行修改
vim /home/ubuntu/.jupyter/jupyter_lab_config.py
修改如下几项配置
- c.ServerApp.ip = '*'
- c.ServerApp.port = 8888
- c.ServerApp.allow_remote_access = True
- c.ServerApp.allow_root = True
重新启动JupyterLab即可.
访问服务器的JupyterLab端口就可以正常登录并使用。
方案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
这样我们本地也可以访问了,流量被远程转发到服务器上。