首页 > 解决方案 > 在 Linux 中启动 Jupyterlab

问题描述

我已经使用anaconda在我的 Ubuntu 20.04 机器上安装了JupyterLab

我想在启动时启动 Jupyterlab。

我可以通过执行以下操作让 Jupyterlab 在启动时运行:

创建文件/etc/systemd/system/jupyter.service

[Unit]
Description=Jupyter Lab
[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/home/USERNAME/anaconda3/envs/jupyterlab/bin/jupyter lab
User=USERNAME
WorkingDirectory=/home/USERNAME/Documents
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target

替换用户名。

然后运行以下命令:

sudo systemctl daemon-reload
sudo systemctl enable jupyter.service
sudo systemctl restart jupyter.service
sudo systemctl status jupyter.service

但是,在 jupyter 笔记本中,如果我运行命令

!python

我得到了我的系统 python,而不是我的 conda 环境 python。

如何在启动时启动 jupyterlab,并且仍然可以!commands按预期工作?

标签: pythonlinuxcondajupyter-lab

解决方案


感谢@krassowski 将ExecStart线路更改为:

ExecStart=/bin/bash -i -c "conda activate jupyterlab;jupyter lab"

解决了我的问题。

IE:

[Unit]
Description=Jupyter Lab

[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/bin/bash -i -c "conda activate jupyterlab;jupyter lab"
User=USERNAME
WorkingDirectory=/home/USERNAME/Documents
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

推荐阅读