Analytics Vidhya
Published in

Analytics Vidhya

Jupyter Lab on Raspberry PI

<span>Photo by <a href=”https://unsplash.com/@harrisonbroadbent?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=c
Photo by Harrison Broadbent on Unsplash

Install Jupyter Lab

$ sudo apt-get update
$ sudo apt-get install python3-pip
$ sudo pip3 install setuptools
$ sudo apt install libffi-dev
$ sudo pip3 install cffi
$ pip3 install jupyterlab
$ mkdir notebooks
$ jupyter lab --notebook-dir=~/notebooks
$ jupyter lab

Setup Jupyter lab as a service

$ which jupyter-lab
/home/pi/.local/bin/jupyter-lab
$ sudo nano /etc/systemd/system/jupyter.service
[Unit]
Description=Jupyter Lab
[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/bin/bash -c "/home/pi/.local/bin/jupyter-lab --ip="0.0.0.0" --no-browser --notebook-dir=/home/pi/notebooks"
User=pi
Group=pi
WorkingDirectory=/home/pi/notebooks
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
$ sudo systemctl enable jupyter.service
$ sudo systemctl daemon-reload
$ sudo systemctl start jupyter.service
$ sudo systemctl stop jupyter.service
$ sudo systemctl status jupyter.servicejupyter.service - Jupyter Notebook
Loaded: loaded (/etc/systemd/system/jupyter.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2020-08-30 16:12:27 PDT; 2s ago
Main PID: 4864 (jupyter-lab)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/jupyter.service
└─4864 /usr/bin/python3 /usr/local/bin/jupyter-lab --ip=0.0.0.0 --no-browser --notebook-dir=/home/pi/notebooks
  1. Add password (easy)
  2. Using SSL for encrypted communication (recommended)
  3. SSH port forwarding (recommended)

Add password

/home/pi/.jupyter/jupyter_notebook_config.py
$ jupyter notebook --generate-config
Writing default config to: /home/pi/.jupyter/jupyter_notebook_config.py
$ jupyter notebook password
Enter password: ****
Verify password: ****
[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json

Using SSL for encrypted communication

SSH port forwarding (tunneling)

<file:/etc/systemd/system/jupyter.service>
...
ExecStart=/bin/bash -c "/usr/local/bin/jupyter-lab --no-browser --notebook-dir=/home/pi/notebooks"
...
ssh -L 8888:localhost:8888 pi@192.168.xx.xx

--

--

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store