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
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
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
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```.
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
```
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".
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!
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/
Network: http://<IP address>:8000/
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
```
Make a symbolic link to the systemd loading folder.
$ sudo ln -s /opt/jupyterhub/etc/systemd/jupyterhub.service /etc/systemd/system/jupyterhub.service
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 ... ```
--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.
-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.
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```.
```Bash
$ pip3 install <library name>
```
Trouble-Shooting
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
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
Try typing the npm command. It's good because the version is displayed normally.
$ sudo npm -v
5.8.0
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/
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
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!
Reference
Recommended Posts