1. 确保 JupyterLab 已安装在 base_env 环境中
首先,激活 base_env 并安装 JupyterLab:
conda activate base_env
conda install jupyterlab -y
验证 JupyterLab 是否可用:
jupyter-lab --version
2. 配置 JupyterLab 启动命令
在 base_env 环境中,确认 JupyterLab 可以正常启动,并在启动时绑定到 0.0.0.0(以便从宿主系统访问):
jupyter-lab --no-browser --ip=0.0.0.0 --port=8888
你可以根据需要调整端口号,例如 8888。
3. 配置开机启动脚本
3.1 创建启动脚本
创建一个启动脚本,用于激活 Conda 环境并启动 JupyterLab。
编辑脚本文件(例如 ~/start_jupyter.sh):
nano ~/start_jupyter.sh
添加以下内容:
#!/bin/bash
# 激活 Conda 环境
source ~/miniconda3/bin/activate base_env
# 启动 JupyterLab
jupyter-lab --no-browser --ip=0.0.0.0 --port=8888
注意:将
~/miniconda3 替换为用户的 Conda 安装路径。
然后赋予脚本执行权限:
chmod +x ~/start_jupyter.sh
3.2 配置脚本为系统服务
使用 systemd 配置脚本在 WSL 启动时自动运行。
编辑一个新的服务文件:
sudo nano /etc/systemd/system/jupyter.service
添加以下内容:
[Unit]
Description=JupyterLab Service
After=network.target
[Service]
Type=simple
ExecStart=/bin/bash -c 'source ~/start_jupyter.sh'
Restart=always
User=your_username
WorkingDirectory=/home/your_username
Environment="PATH=/home/your_username/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
[Install]
WantedBy=default.target
将 your_username 替换为实际用户名。
3.3 启用和启动服务
启用服务以便开机运行:
sudo systemctl enable jupyter.service
立即启动服务以验证是否工作:
sudo systemctl start jupyter.service
检查服务状态:
sudo systemctl status jupyter.service
应该能看到 JupyterLab 已经启动,并在指定的端口运行。
4. 测试效果
重启 WSL:
wsl --shutdown
wsl
在宿主机浏览器中访问:http://localhost:8888。
1220

被折叠的 条评论
为什么被折叠?



