服务器使用jupyterlab

该文详细介绍了如何在服务器虚拟环境下安装JupyterLab,包括激活环境、安装所需软件、生成配置文件、设置密码,以及启动和配置kernel。此外,还阐述了如何通过浏览器远程访问并使用JupyterLab,以及关闭服务的方法。

1.在服务器虚拟环境下安装jupyterlab

conda activate xxx
pip install jupyterlab

2.配置jupyterlab

(1)生成jupyterlab的配置文件

jupyter notebook --generate-config 
# 显示
Writing default config to: /root/.jupyter/jupyter_notebook_config.py

(2)设置密码

jupyter notebook password
# 显示
Enter password: 输入密码
Verify password: 再次输入密码进行确认
# 最终显示
[NotebookPasswordApp] Wrote hashed password to /root/.jupyter/jupyter_notebook_config.json

3.服务器端启动jupyterlab

(1)安装ipykernel

pip install ipykernel

(2)将环境写入jupyterlab的kernel核中

python -m ipykernel install --user --name 环境名称 --display-name "显示的名称"
# 例:
# python -m ipykernel install --user --name xxx --display-name "xxx_jupyterlab"

启动jupyter-lab之后,在这个xxx环境安装的包都可以使用

(3)进入到自己的文件夹内

cd 目标文件夹

(4)启动jupyterlab

启动jupyter-lab命令(ip不可更改,port可更改):

jupyter-lab --ip 0.0.0.0 --port 8888 --no-browser --allow-root

然后打开本地浏览器输入:ip地址:端口号 这里的IP地址是指你服务器的ip地址(你在哪个服务器上启动了jupyter-lab),端口号就是启动jupyter-lab时指定的端口号,这里为8888。

4.网页端启动jupyterlab

在本地计算机打开浏览器后,在地址栏输入:

服务器IP:8888

输入之前在第2-2步设置的密码即可,跳转至网页版jupyterlab。

如果你的目录下有文件的话,将全部显示在左侧。双击代码文件,就可以调试运行啦!

5.关闭jupyterlab服务

在控制台使用快捷键ctrl+C,再输入y确认即可。

### 如何在服务器上安装和配置 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 界面。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值