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