Starting Jupyterlab on boot in Linux

Viewed 523

I have installed JupyterLab on my Ubuntu 20.04 machine using anaconda.

I would like to start Jupyterlab on boot.

I CAN get Jupyterlab to run on boot by doing the following:

Create the file /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

replacing USERNAME.

Then run the following commands:

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

HOWEVER, in a jupyter notebook, if I run the command

!python

I get my system python, not my conda environment python.

How can I start jupyterlab on boot, and still get !commands to work as expected?

1 Answers

Thanks to @krassowski changing the ExecStart line to:

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

solved my problem.

i.e.:

[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
Related