Jupyterlab是JupyterNotebook的升级版本,功能更强大,更人性化。下面介绍如何在无桌面环境的ubuntu服务器下配置jupyterlab服务,实现开机启动jupyterlab服务。
1.首先安装jupyter
#有conda虚拟环境的用户需要先激活虚拟环境:conda activate envname
pip install jupyterlab
2.生成配置文件
jupyter-lab --generate-config #生成配置文件
3.修改部分参数
vim ~/.jupyter/jupyter_notebook_config.py
c.NotebookApp.default_url = '/lab' #"/lab"启动Jupyterlab, “/tree”则启动JupyterNotebook
c.NotebookApp.ip = '*' # 允许所有IP访问,“localhost” 则只允许本机访问
c.NotebookApp.notebook_dir = '/home/test/pypro' #启动后的根目录
c.NotebookApp.open_browser = False #启动后不打开浏览器
## Hashed password to use for web authentication.
#
# To generate, type in a python/IPython shell:
#
# from notebook.auth import passwd; passwd()
#
# The string should be of the form type:salt:hashed-password.
#c.NotebookApp.password = ''
c.NotebookApp.password = '' #预设的密码,通过上面的命令设置
## The port the notebook server will listen on.
c.NotebookApp.port = 8888 #默认的端口,当主机运行多个jupyterlab时要确保端口不被占用.不能和其它的jupyterlab的端口相同.
4.写一个 jupyterlab.service 文件实现开机启动
#在/lib/systemd/system 目录下新建 jupyterlab.service 文件,内容如下
[Unit]
Description=Jupyter Notebook
After=network.target
[Service]
Type=simple
PIDFile=/home/test/.jupyter/jupyter.pid
ExecStart=/opt/anaconda3/bin/jupyter-lab --config=/home/test/.jupyter/jupyter_notebook_config.py
User=test
Group=test
WorkingDirectory=/pypro
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
将上面的 test,替换为自己的用户名,WorkingDirectory替换为自己的项目路径
5.启动jupyterlab,添加开机启动项。
systemctl start jupyterlab.service #启动jupyterlab
systemctl enable jupyterlab.service #添加到开机服务中
完成后即可实现其他主机访问 本机ip:8888 来远程使用Jupyterlab