JupyterLab安装、虚拟环境配置及后台开机自启动
Jupyterlab是一个交互式笔记本,是jupyter notebook的进阶版,支持运行40多种编程语言,本质是一个Web应用程序,便于创建和共享文学化程序文档,支持实时代码,数学方程,可视化和Markdown。Jupyterlab还支持插件,已经是一个具备在线远程交互的IDE,非常有助于debug,极其推荐!!!
一、安装
conda install -c conda-forge jupyterlab # 主程序安装
二、配置
1. 生成默认配置文件 ~/.jupyter/jupyter_lab_config.py
jupyter-lab --generate-config
2. 修改配置文件 vim ~/.jupyter/jupyter_lab_config.py
# 考虑修改服务器默认目录
c.ServerApp.root_dir= '/home/user/projects
# 修改默认端口,以免被别人进入自己的notebook
# 尤其是服务器,要修改端口避免冲突
c.ServerApp.port = 8889
# 设置notebook可登陆的ip, 全0为不限制
c.ServerApp.ip = '0.0.0.0'
# 关闭登陆密码,确保本地安全才可以,否则切勿关闭
c.ServerApp.token = ''
服务器运行指令 jupyter-lab --no-browser
浏览器输入 server_ip:port
3. 配置虚拟环境
-
查看环境
jupyter-kernelspec list
-
安装环境
默认情况下,只有Python3一个kernel。如果想要添加其他kernel,则需要添加本地虚拟环境。conda install ipykernel # 安装管理包 python3.* -m ipykernel install --user --name 环境名称 --display-name "在jupyter中显示的环境名称"
注: 要设置python3.* 为conda虚拟环境内的包,不然启动位置会出错,可以指定/path/to/your_python
-
卸载环境
jupyter-kernelspec remove {jupyter_env_name}
三、Linux设置Jupyterlab开机自启动(可选)
以服务的形式,配置开机启动项
sudo vim /etc/systemd/system/jupyter.service
添加如下代码:
- waa为我的用户名,注意修改
- jupyter-lab路径,可通过
which jupyter-lab
查看 - WorkingDirectory 可自行设定
[Unit]
Description=Jupyterlab
After=network.target
[Service]
Type=simple
ExecStart=/home/waa/.conda/envs/imb/bin/jupyter-lab --config=/home/waa/.jupyter/jupyter_lab_config.py --no-browser
User=waa
Group=waa
WorkingDirectory=/home/waa/Projects/
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
设置自启动
sudo systemctl enable jupyter (开机自启动)
sudo systemctl start jupyter (启动)
本文来自博客园,作者:Tsingwaa,转载请注明原文链接:https://www.cnblogs.com/Tsingwaa/articles/14681660.html