JupyterLab的安装与配置
1 安装
我使用的Python是Miniconda安装的,包的管理使用 conda
。所以安装比较简单,一行命令搞定。
conda install jupyterlab
2 配置远程访问
2.1 生成一个配置文件
默认情况下,配置文件 ~/.jupyter/jupyter_notebook_config.py
并不存在,需要自行创建。使用下列命令生成配置文件:
jupyter notebook --generate-config
2.2 生成密码
从 jupyter lab 3.0 版本开始,提供了一个命令来设置密码:jupyter lab password
,生成的密码存储在jupyter_notebook_config.json
。
jupyter lab password
2.3 修改配置文件
在jupyter_notebook_config.py
中找到下面的行,取消注释并修改。
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888 #可自行指定一个端口, 访问时使用该端口
3 插件安装
安装插件之前,如果没 nodejs
可以先安装nodejs。安装方法如下:
conda install nodejs
安装之后添加nodejs的国内镜像。
# 添加淘宝镜像源
npm config set registry https://registry.npm.taobao.org
# 验证是否安装成功
npm config get registry
4 后台运行
和其普通程序一样,后台运行,并重定向log
nohup jupyter lab 2>&1 >> ~/logs/jupyter.log &
5 开机启动
如果你想开机启动,那么就进行如下的操作:
5.1 找到JupyterLab安装位置
which jupyter-lab
5.2 创建jupyter.service文件
使用如下命令编辑jupyter.service
文件:
sudo vim /etc/systemd/system/jupyter.service
在文件中复制如下内容
[Unit]
Description=Jupyter Notebook
After=network.target
[Service]
Type=simple
User=selfcs
ExecStart=/home/selfcs/miniconda3/bin/jupyter-lab --port 8888
WorkingDirectory=/home/selfcs
[Install]
WantedBy=default.target
注意:
User
需要更换为自己的用户名。ExexStart
需要更换为自己的JupyterLab路径。WorkingDirectory
按照自己的工作路径更换。
5.3 服务启动与检查
分别输入以下两个命令启动服务:
sudo systemctl enable jupyter
sudo systemctl start jupyter
使用如下命令检查服务是否正常启动:
sudo systemctl status jupyter
如需关闭JupyterLab使用如下命令
sudo systemctl stop jupyter