服务器开启jupyterlab

本文详细介绍如何安装JupyterLab,生成配置文件,并通过修改配置实现远程访问。包括设置密码、更改监听IP、端口等步骤,以及如何为不同Python环境添加Kernel。

安装jupyterlab:

pip install jupyterlab

生成配置文件,并记下输出的配置文件地址,一般是在~/.jupyter/jupyter_lab_config.py

jupyter lab --generate-config

打开python解释器,输入:

from jupyter_server.auth import passwd
passwd()

此时会让你设置密码,设置完成后会得到hash好的密码,将其复制:

'sha1:0d46e59c26c6:caab7b48941bee0095bdcf0747cd2a5a22a27581'

修改配置文件,添加下列配置,其中的密码写入hash好的密码,而不是你设置的密码:

c.ServerApp.allow_root = True
c.ServerApp.ip = '0.0.0.0'
c.ServerApp.notebook_dir = "/"
c.ServerApp.open_browser = False
c.ServerApp.port = 9001
c.ServerApp.password = '***'

shell内执行下行命令,即可开启jupyter lab:

jupyter lab

在浏览器内输入服务器IP和端口号,输入你之前设置的密码,即可访问jupyter lab。

此时,jupyter lab内的kernal只有开启这个jupyter lab的python环境。
如果要添加其他kernel,需要先conda activate想要添加的python环境,并执行下列指令:

pip install ipykernel
python -m ipykernel install --user --name xxxx(kernal会显示的名字)
### 如何在服务器上安装和配置 JupyterLab #### 安装 JupyterLab JupyterLabJupyter Notebook 的升级版,提供了更强大的功能、更灵活的布局和更现代化的用户界面[^1]。要安装 JupyterLab,可以使用 `pip` 或 `conda` 包管理器。 以下是基于 `conda` 的安装方法: ```bash # 创建一个新的 conda 环境(可选) conda create -n jupyterlab_env python=3.9 # 激活环境 conda activate jupyterlab_env # 安装 JupyterLab conda install -c conda-forge jupyterlab ``` 如果是基于 `pip` 的安装: ```bash pip install jupyterlab ``` #### 配置 JupyterLab 为了在服务器上运行 JupyterLab,需要进行一些额外的配置以确保安全性并允许远程访问。 1. **生成配置文件** 使用以下命令生成配置文件: ```bash jupyter lab --generate-config ``` 这将在 `~/.jupyter/` 目录下生成一个名为 `jupyter_lab_config.py` 的文件[^2]。 2. **编辑配置文件** 打开配置文件并进行必要的修改。例如,设置密码和允许远程访问: ```python # 设置密码 c.ServerApp.password = 'sha1:your_hashed_password_here' # 允许远程访问 c.ServerApp.ip = '0.0.0.0' c.ServerApp.open_browser = False c.ServerApp.port = 8888 # 自定义端口 c.ServerApp.allow_remote_access = True ``` 注意:为了生成安全的密码哈希值,可以使用以下命令: ```bash from notebook.auth import passwd passwd() ``` 3. **配置系统服务(可选)** 如果希望 JupyterLab 在后台持续运行,可以将其配置为系统服务。以下是一个示例配置文件[^3]: ```ini [Unit] Description=JupyterLab Service [Service] Type=simple PIDFile=/run/jupyter.pid ExecStart=/home/sxyd/miniconda3/envs/jupyterlab/bin/jupyter lab --config=/home/sxyd/.jupyter/jupyter_lab_config.py User=sxyd Group=sxyd WorkingDirectory=/home/sxyd/ Restart=always RestartSec=10 [Install] WantedBy=multi-user.target ``` 将上述内容保存为 `/etc/systemd/system/jupyterlab.service`,然后执行以下命令启动服务: ```bash sudo systemctl daemon-reload sudo systemctl start jupyterlab sudo systemctl enable jupyterlab ``` #### 启动与访问 完成配置后,可以通过以下命令启动 JupyterLab: ```bash jupyter lab ``` 如果配置了系统服务,则无需手动启动。通过浏览器访问服务器IP 地址和指定的端口(如 `http://<server-ip>:8888`),即可打开 JupyterLab 界面。 ---
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值