Create a Python multi-user platform with JupyterHub + JupyterLab on Rapsberry Pi 3B +!

Introduction

Setting up a VM is a hassle. But I want to make a Python development environment ** cheap ** for multiple people. Qiita for those who are worried. It is a memo for myself.

Hopefully ** it will take about an hour **.

Material --Raspberry Pi3 + (I really wanted Raspberry Pi4 Memory: 4GB)

Method

Environment

  1. First, use apt to install the necessary set on jupyterhub.

    $ sudo apt update
    $ sudo apt upgrade
    $ sudo apt install python3 python3-pip npm nodejs libnode64
    
  2. Next, use pip3 and npm to install the jupyterhub set and proxy function. # 1

    $ sudo pip3 install jupyterhub notebook wheel ipywidgets jupyterlab
    $ sudo npm install -g configurable-http-proxy
    
  3. Start JupyterHub locally and check the operation. First, check with a general user.

    $ /usr/local/bin/jupyterhub
    

Then, in Chromium on the Raspberry Pi Desktop, go to http: // localhost: 8000 / and check that the following screen appears. The JupyterHub server can be terminated with `` `ctrl-c```. Screen Shot 2020-02-22 at 23.50.49.png

To use it as multiple user, you need to start it as root user. So, start it as root (sudo) and check again that the above login screen is displayed.

```Bash
$ sudo jupyterhub
```
  1. In order to configure JupyterHub, create the source of the configuration file in "/ etc / jupyterhub".

    $ sudo mkdir /etc/jupyterhub
    $ cd /etc/jupyterhub
    $ sudo jupyterhub --generate-config    #Have this command create a default config file
    

Then "jupyterhub_config.py" is spit out. Open it as root user and fix the following:

```Bash
$ sudo vi /etc/jupyterhub/jupyterhub_config.py    #vi or whatever you like with your favorite text editor
```
```/etc/jupyterhub/jupyterhub_config.py
#I want to use jupyter lab by default, so modify the following
c.Spawner.default_url = '/lab' 

#Add accessible users to the whitelist
c.Authenticator.whitelist = {'User1, User2'}

#Add admin user(Authorized to disconnect general users)
c.Authenticator.admin_users = {'User0'}

#Set to refer to the notebook folder of each user directory when accessed
#It's not a mandatory setting item, but a place where preferences are divided.
c.Spawner.notebook_dir = '~/notebook'
```

If'c.Spawner.notebook_dir'is set,'each user's notebook directory (~ / notebook) must be created in advance. (Reference site: https://qiita.com/atsushi_wagatsuma/items/89b714328663992b54f4)

For detailed user management, refer to this article "Adding and Removing Users".

  1. Finally, start jupyterhub and check the operation.

    $ sudo jupyterhub -f /etc/jupyterhub/jupyterhub_config.py
    ...
    [I 2020-02-23 11:10:12.687 JupyterHub app:2631] JupyterHub is now running at http://:8000    #If this display appears, startup is complete!
    
  2. Check if the Admin user and general user can log in from localhost or another computer on the network. If you write a simple Python program and it works, it's OK! Localhost:http://localhost:8000/ Screen Shot 2020-02-23 at 12.06.18.png Network: http://<IP address>:8000/ Screen Shot 2020-02-23 at 12.22.17.png

  3. It worked for the time being, but if you keep it, you have to type `` `$ sudo jupyterhub -f /etc/jupyterhub/jupyterhub_config.py``` every time you start up. Very annoying. Therefore, it is managed centrally by Systemd service and set to start automatically when Raspberry pi starts.

    $ sudo mkdir -p /opt/jupyterhub/etc/systemd    #According to the convention, create a folder like this under opt and put the configuration file there.
    $ sudo vi /opt/jupyterhub/etc/systemd/jupyterhub.service    #Create a new file with a Text Editor such as vi and copy and paste the following entry.
    
    [Unit]
    Description=JupyterHub
    After=syslog.target network.target
    
    [Service]
    User=root 
    

Environment="PATH=/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin" ExecStart=/usr/local/bin/jupyterhub -f /etc/jupyterhub/jupyterhub_config.py

[Install]
WantedBy=multi-user.target
```
  1. Make a symbolic link to the systemd loading folder.

    $ sudo ln -s /opt/jupyterhub/etc/systemd/jupyterhub.service /etc/systemd/system/jupyterhub.service
    
  2. Reload the configuration file with systmctl. And set to automatically start jupyterhub when Raspberry Pi starts. In addition, try starting it manually for the time being.

    $ sudo systemctl daemon-reload    # config.Reload the file
    $ sudo systemctl enable jupyterhub.service    #Jupyterhub at startup.service starts automatically
    $ sudo systemctl start jupyterhub.service    # jupyterhub.Manual start of service
    $ sudo systemctl status jupyterhub.service    #jupyterhub.Check the status of service.
    
    # "Active: active (runnning)"Is displayed, OK
    
    ● jupyterhub.service - JupyterHub
    

Loaded: loaded (/opt/jupyterhub/etc/systemd/jupyterhub.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2020-02-23 13:11:01 JST; 10s ago ... ```

Add / remove users

--By default, you can select a user who can access JupyterHub from Unix users on the server where JupyterHub is installed. --Which Unix user can access the JupyterHub ** server startup ** is the `` c.Authenticator.whitelist``` in the above `/etc/jupyterhub/jupyterhub_config.py```. Added to.

--The admin user is running while the jupyterHub server is running You can manage the addition / deletion of users on the Jupyterhub WebApp, but be aware that this setting will be reset ** when you restart the jupyterHub server. Screen Shot 2020-02-23 at 13.15.26.png

-Official Web Document has more information. ** A must read for those who manage it in earnest. ** **

Jupyterlab/hub-extension As of 2020.02.23, you can move to the Hub setting screen from `File-> Hub Control Panel` of Jupyterlab. Don't you need Jupyterlab / hub-extension?

Postscript (2020.02.23) Officially, this extension seems to have been integrated into Jupyterlab. Therefore, there is no need to install it. GitHub: jupyterlab/jupyterlab

This adds a "Hub" menu to JupyterLab that allows a user to log out of JupyterHub or access their JupyterHub control panel.

Screen Shot 2020-02-23 at 13.33.15 2.png

Screen Shot 2020-02-23 at 13.41.20.png

Python Library Note: I'm a `` `pipsect, so I'll just describe it. If you are a member of the Conda``` group, please google ... m (_ _) m

--The Library you want to apply to all users is installed and managed with sudo.

```Bash
$ sudo pip3 install <library name>
```

--The Python Library that you want to install and manage for each user is entered by individually typing commands for each user using `` `JupyterLab-> Launcher-> Other-> Terminal```. Screen Shot 2020-02-23 at 14.38.08.png

```Bash
$ pip3 install <library name>
```

Trouble-Shooting

Does not start with Proxy related error

  1. When I tried to start Jupyterhub, I got a proxy related error code and could not start it. I thought that npm was the cause, so I typed the npm command, but pear gravel.

    $ sudo npm
    $                   #Nothing is displayed
    
  2. There is no help for it, so delete the npn / node / nodejs related items and reinstall.

    $ sudo apt remove node npm nodejs
    $ sudo apt update     #Update the list for the time being
    $ sudo apt upgrade    #For the time being, the latest version
    $ sudo apt install node libnode64 npm
    
  3. Try typing the npm command. It's good because the version is displayed normally.

    $ sudo npm -v
    5.8.0
    
  4. If you hit only npm, you will get a warning that "npm and Node.js versions do not match". This may cause problems in the future, but jupyterhub works for the time being.

    $ sudo npm
    npm WARN npm npm does not support Node.js v10.15.2
    npm WARN npm You should probably upgrade to a newer version of node as we
    npm WARN npm can't make any promises that npm will work with this version.
    npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.
    npm WARN npm You can find the latest version at https://nodejs.org/
    
  5. Start jupyterhub and check if it starts normally.

    $ sudo jupyterhub -f /etc/jupyterhub/jupyterhub_config.py
    ...
    [I 2020-02-23 11:10:12.687 JupyterHub app:2631] JupyterHub is now running at http://:8000
    

Screen Shot 2020-02-22 at 23.50.49.png

jupyterlab Extension, jupyterlab-drawio cannot be installed

Probably due to the problem that the above Node.js and npm versions don't match and can't rebuild? Currently no action (as of February 23, 2020).

Great Web references for JupyterLab/Python A great site for those who are new to JupyterLab / Python!

  1. Jupyter Lab Recommendation
  2. Kyoto University Lecture Material: Programming Exercise Python 2019

Reference

  1. JupyterHub Quickstart
  2. JupyterHub Official page

Recommended Posts

Create a Python multi-user platform with JupyterHub + JupyterLab on Rapsberry Pi 3B +!
Create a classroom on Jupyterhub
Create a directory with python
Create a list in Python with all followers on twitter
getrpimodel: Recognize Raspberry Pi model (A, B, B +, B2, B3, etc) with python
Create a Python environment on Mac (2017/4)
Create a virtual environment with Python!
Create a Python function decorator with Class
Build a blockchain with Python ① Create a class
Create a dummy image with Python + PIL.
Create a python environment on your Mac
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
A memo with Python2.7 and Python3 on CentOS
Map rent information on a map with python
Create a word frequency counter with Python 3.4
Create a car meter with raspberry pi
Working with GPS on Raspberry Pi 3 Python
Detect analog signals with A / D converter using python on Raspberry Pi 3!
Steps to create a Python virtual environment with VS Code on Windows
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Create a LINE BOT with Minette for Python
Build a python environment with ansible on centos6
Create a page that loads infinitely with python
[Note] Create a one-line timezone class with python
You can easily create a GUI with Python
Create a python3 build environment with Sublime Text3
Create a color bar with Python + Qt (PySide)
Folium: Visualize data on a map with Python
Steps to create a Twitter bot with python
[Venv] Create a python virtual environment on Ubuntu
Create a decision tree from 0 with Python (1. Overview)
Create a new page in confluence with Python
Create a color-specified widget with Python + Qt (PySide)
Create a Photoshop format file (.psd) with python
Create a Python console application easily with Click
Decrypt a string encrypted on iOS with Python
Create a Python execution environment on IBM i
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Create a Python virtual development environment on Windows
Connect to MySQL with Python on Raspberry Pi
Visualize grib2 on a map with python (matplotlib)
Build a Python development environment on Raspberry Pi
GPS tracking with Raspberry Pi 4B + BU-353S4 (Python)
[Note] Use a wired LAN connection device with WiFi-Eth bridge on Raspberry Pi 4B
Until you create a machine learning environment with Python on Windows 7 and run it
Run LEDmatrix interactively with Raspberry Pi 3B + on Slackbot
Try debugging Python on Raspberry Pi with Visual Studio.
[Python] Create a ValueObject with a complete constructor using dataclasses
Why not create a stylish table easily with Python?
Create a comfortable Python 3 (Anaconda) development environment on windows
Create a python development environment with vagrant + ansible + fabric
Make a breakpoint on the c layer with python
I made a Python3 environment on Ubuntu with direnv.
Create a Layer for AWS Lambda Python with Docker
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
[python] Create a date array with arbitrary increments with np.arange
A note on speeding up Python code with Numba
[Python] How to create a 2D histogram with Matplotlib
[Python] Create a Tkinter program distribution file with cx_Freeze
Create a decent shell and python environment on Windows