|
|
# Installation von »Jupyter Lab«
|
|
# Installation von »Jupyter Lab«
|
|
|
|
|
|
|
|
**Wichtiger Hinweis**: Die im Folgenden beschriebenen Anweisungen zur
|
|
»Jupyter Lab« ist eine web-basierte interaktive Umgebung zur Erzeugung von Jupyter-Notebook-Dokumenten (oft Python-Programme mit zugehöriger
|
|
|
Installation des eigentlichen »Jupyter Lab« (nicht Apache usw.) sind nicht
|
|
|
|
|
mehr aktuell. Stattdessen ist so vorzugehen, wie im Abschnitt »Installation
|
|
|
|
|
›Jupyter Lab‹ (März 2023)« beschrieben wird.
|
|
|
|
|
|
|
|
|
|
## Jupyter Notebook
|
|
|
|
|
|
|
|
|
|
»Jupyter Notebook« ist eine web-basierte interaktive Umgebung zur Erzeugung von
|
|
|
|
|
Jupyter-Notebook-Dokumenten (oft Python-Programme mit zugehöriger
|
|
|
|
|
Dokumentation).
|
|
Dokumentation).
|
|
|
|
|
|
|
|
Nachfolgend werden Hinweise zur Installation unter openSUSE 15.1 gegeben. Sie
|
|
Nachfolgend werden Hinweise zur Installation unter openSUSE 15.5 gegeben. Sie gelten sinngemäß auch für andere systemd-basierte Linux-Distributionen.
|
|
|
gelten sinngemäß auch für andere systemd-basierte Linux-Distributionen.
|
|
|
|
|
|
|
|
|
|
### Installation der nötigen Pakete
|
|
|
|
|
```
|
|
|
|
|
zypper in --recommends apache2 python3-jupyter_ipython
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Apache-Konfiguration eines virtuellen Hosts für »Jupyter Notebook« (Port 82)
|
|
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
cat <<EOF > /etc/apache2/vhosts.d/notebook.conf
|
|
|
|
|
Listen 82
|
|
|
|
|
|
|
|
|
|
<VirtualHost *:82>
|
|
## Installation der nötiger System-Pakete
|
|
|
ProxyPass / http://127.0.0.1:8888/
|
|
|
|
|
ProxyPassReverse / http://127.0.0.1:8888/
|
|
|
|
|
# spoof headers to make notepad accept the request as coming from the same origin
|
|
|
|
|
Header set Origin "http://127.0.0.1:8888/"
|
|
|
|
|
RequestHeader set Origin "http://127.0.0.1:8888/"
|
|
|
|
|
LogLevel debug
|
|
|
|
|
<Location /api/kernels/>
|
|
|
|
|
ProxyPass ws://127.0.0.1:8888/api/kernels/
|
|
|
|
|
ProxyPassReverse ws://127.0.0.1:8888/api/kernels/
|
|
|
|
|
</Location>
|
|
|
|
|
<Location /ipython/terminals/websocket/>
|
|
|
|
|
ProxyPass ws://127.0.0.1:8888/ipython/terminals/websocket/
|
|
|
|
|
ProxyPassReverse ws://127.0.0.1:8888/ipython/terminals/websocket/
|
|
|
|
|
</Location>
|
|
|
|
|
</VirtualHost>
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
```
|
|
```
|
|
|
|
|
zypper in --recommends apache2 inkscape python311-base pandoc
|
|
|
### Systemd-Service-Datei zum Starten oder Stoppen des Servers
|
|
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
cat <<EOF > /usr/lib/systemd/system/ipython-notebook.service
|
|
|
|
|
# README:
|
|
|
|
|
# Copy this file to /usr/lib/systemd/system/
|
|
|
|
|
# sudo systemctl daemon-reload
|
|
|
|
|
# systemctl enable ipython-notebook
|
|
|
|
|
# systemctl start ipython-notebook
|
|
|
|
|
# The WorkingDirectory and ipython-dir must exist
|
|
|
|
|
# If you don't want anything fancy, go to http://127.0.0.1:8888 to see your notebook
|
|
|
|
|
# wheneber you want it
|
|
|
|
|
|
|
|
|
|
[Unit]
|
|
Anmerkung: Mit Pythonversionen <= 3.6 gab es Probleme.
|
|
|
Description=IPython notebook
|
|
|
|
|
|
|
|
|
|
[Service]
|
|
## Apache-Server als Proxy einrichten.
|
|
|
Type=simple
|
|
|
|
|
PIDFile=/var/run/ipython-notebook.pid
|
|
|
|
|
ExecStart=/usr/bin/jupyter notebook --notebook-dir=/home/ipynb/notebooks --no-browser --profile=nbserver --NotebookApp.allow_origin="http://127.0.0.1:82"
|
|
|
|
|
User=ipynb
|
|
|
|
|
Group=ipynb
|
|
|
|
|
WorkingDirectory=/home/ipynb/notebooks
|
|
|
|
|
|
|
|
|
|
[Install]
|
|
Im Verzeichnis `/etc/apache2/vhosts.d` ist die Datei `jupyterlab.conf` mit folgendem Inhalt zu erstellen:
|
|
|
WantedBy=multi-user.target
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
```
|
|
```
|
|
|
|
Listen 82
|
|
|
|
|
|
|
|
### Konfiguration
|
|
<VirtualHost *:82>
|
|
|
|
<Location ~ "/(user/[^/]+)/(api/kernels/[^/]+/channels|terminals/websocket)/?">
|
|
|
|
ProxyPass ws://127.0.0.1:8888
|
|
|
|
ProxyPassReverse ws://127.0.0.1:8888
|
|
|
|
</Location>
|
|
|
|
ProxyPass / http://127.0.0.1:8888/
|
|
|
|
ProxyPassReverse / http://127.0.0.1:8888/
|
|
|
|
|
|
|
|
Das Folgende ist unter dem root-Account bzw. mit root-Rechten auszuführen:
|
|
Header edit Origin a73435.berlin.ptb.de:82 127.0.0.1:8888
|
|
|
|
RequestHeader edit Origin a73435.berlin.ptb.de:82 127.0.0.1:8888
|
|
|
|
|
|
|
|
```bash
|
|
Header edit Referer a73435.berlin.ptb.de:82 127.0.0.1:8888
|
|
|
a2enmod proxy
|
|
RequestHeader edit Referer a73435.berlin.ptb.de:82 127.0.0.1:8888
|
|
|
a2enmod proxy_html
|
|
|
|
|
a2enmod proxy_http
|
|
|
|
|
a2enmod headers
|
|
|
|
|
a2enmod proxy_wstunnel
|
|
|
|
|
|
|
|
|
|
useradd --create-home --system --user-group ipynb
|
|
LogLevel debug
|
|
|
mkdir /home/ipynb/notebooks
|
|
</VirtualHost>
|
|
|
chown -R ipynb.ipynb /home/ipynb
|
|
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
Das Folgende ist unter dem Account des Nutzers »ipynb« auszuführen:
|
|
Anmerkung: Statt des Ports 82 kann auch ein anderer gewählt werden.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
su - ipynb
|
|
|
|
|
|
|
|
|
|
ipython profile create nbserver
|
|
|
|
|
|
|
|
|
|
# Setzen des Passworts
|
|
Desweiteren sind einige Apache-Module zu aktivieren
|
|
|
python3
|
|
|
|
|
Python 3.5.2 (default, Sep 14 2016, 11:28:32)
|
|
|
|
|
[GCC 6.2.1 20160901 (Red Hat 6.2.1-1)] on linux
|
|
|
|
|
Type "help", "copyright", "credits" or "license" for more information.
|
|
|
|
|
>>> from notebook.auth import passwd
|
|
|
|
|
>>> passwd() # below I enter "password123"
|
|
|
|
|
Enter password:
|
|
|
|
|
Verify password:
|
|
|
|
|
'sha1:????????????:??????'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
In `/home/ipynb/.jupyter/jupyter_notebook_config.py` ist einzutragen (unbedingt unter
|
|
|
|
|
ipynb-Account):
|
|
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
c.NotebookApp.password = 'sha1:????????????:??????'
|
|
a2enmod mod_proxy_wstunnel proxy proxy_http headers proxy_wstunnel
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
Das Folgende ist unter dem root-Account bzw. mit root-Rechten auszuführen:
|
|
und der Apache-Prozess ist neu zu starten:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
systemctl enable apache2.service
|
|
|
|
|
systemctl start apache2.service
|
|
|
|
|
systemctl enable ipython-notebook.service
|
|
|
|
|
systemctl start ipython-notebook.service
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Zugriff
|
|
|
|
|
|
|
|
|
|
Der Serverzugriff entsprechend der hier gezeigten Installation erfolgt über
|
|
|
|
|
`http://HOSTNAME:82/`.
|
|
|
|
|
|
|
|
|
|
## Jupyter Lab
|
|
|
|
|
|
|
|
|
|
Die Installation von »Jupyter Lab« geschieht weitgehend in derselben Weise wie
|
|
|
|
|
»Jupyter Notebook«. In Folgenden werden nur die Unterschiede aufgeführt.
|
|
|
|
|
|
|
|
|
|
### Installation der nötigen Pakete
|
|
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
zypper in python3-pip
|
|
systemctl restart apache2.service
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
Sofern als Systempaket angeboten:
|
|
Dies bewirkt, dass künftig alle Anfragen an `http://a73435.berlin.ptb.de:82/` nach `http://127.0.0.1:8888/` umgeleitet werden.
|
|
|
```
|
|
|
|
|
zypper in --recommends jupyter-jupyterlab
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Im anderen Fall:
|
|
## Installation der Komponenten von »Jupyter Lab«
|
|
|
```
|
|
|
|
|
pip3 install jupyterlab
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Zusätzlich (laborspezifisch) ist noch Folgendes zu tun:
|
|
### Anlegen einer virtuellen Python-Umgebung
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
npm install yarn -g
|
|
cd /usr/local/share/
|
|
|
pip3 install ipympl
|
|
/usr/bin/python3.11 -m venv JupyterLab
|
|
|
jupyter lab build
|
|
|
|
|
#su - ipynb # ???
|
|
|
|
|
cd /home/ipynb/notebooks
|
|
|
|
|
GIT_SSL_NO_VERIFY=true git clone https://a75436.berlin.ptb.de/vaclab/vpy.git
|
|
|
|
|
cd vpy
|
|
|
|
|
pip3 install -e .
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Systemd-Service-Datei zum Starten oder Stoppen des Servers
|
|
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
cat <<EOF > /usr/lib/systemd/system/ipython-lab.service
|
|
|
|
|
# README:
|
|
|
|
|
# Copy this file to /usr/lib/systemd/system/
|
|
|
|
|
# sudo systemctl daemon-reload
|
|
|
|
|
# systemctl enable ipython-notebook
|
|
|
|
|
# systemctl start ipython-notebook
|
|
|
|
|
# The WorkingDirectory and ipython-dir must exist
|
|
|
|
|
# If you don't want anything fancy, go to http://127.0.0.1:8888 to see your notebook
|
|
|
|
|
# wheneber you want it
|
|
|
|
|
|
|
|
|
|
[Unit]
|
|
|
|
|
Description=IPython notebook
|
|
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
|
Type=simple
|
|
|
|
|
PIDFile=/var/run/ipython-notebook.pid
|
|
|
|
|
ExecStart=/usr/bin/jupyter lab --notebook-dir=/home/ipynb/notebooks --no-browser --profile=nbserver --NotebookApp.allow_origin="http://127.0.0.1:82"
|
|
|
|
|
User=ipynb
|
|
|
|
|
Group=ipynb
|
|
|
|
|
WorkingDirectory=/home/ipynb/notebooks
|
|
|
|
|
|
|
|
|
|
[Install]
|
|
### Installation der nötigen Python-Bibliotheken
|
|
|
WantedBy=multi-user.target
|
|
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
```
|
|
```
|
|
|
|
|
source ./bin/activate
|
|
|
### Konfiguration
|
|
python3 -m pip install --upgrade pip
|
|
|
|
|
pip3 install jupyterlab nbconvert
|
|
|
Das Folgende ist unter dem root-Account bzw. mit root-Rechten auszuführen:
|
|
# Zusätzliche Nutzer-Bibliotheken:
|
|
|
|
|
pip3 install matplotlib statistics datetime numpy sympy pandas couchdb
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
systemctl enable ipython-lab.service
|
|
|
|
|
systemctl start ipython-lab.service
|
|
|
|
|
systemctl status ipython-lab.service
|
|
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
## Installation »Jupyter Lab« (März 2023)
|
|
### Erzeugen eines Passwortes
|
|
|
|
|
|
|
|
Es hat sich herausgestellt, dass die Installation nur auf Basis von
|
|
|
|
|
Systempaketen nicht gut gelingt (weitere Python-Bibliotheken müssen per `pip`
|
|
|
|
|
installiert werden). Das wiederum führt möglicherweise zu schwer zu
|
|
|
|
|
behebenden Konflikten. Ein bessere Lösung ist daher, den »Jupyter Lab«-Server
|
|
|
|
|
gänzlich in einer virtuellen Python-Umgebung laufen zu lassen. Eine solche
|
|
|
|
|
Installation wird im Folgenden beschrieben. Alle nachfolgenden Befehle müssen
|
|
|
|
|
mit root-Privilegien ausgeführt werden:
|
|
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
ssh root@a73435
|
|
JUPYTER_CONFIG_DIR=$PWD jupyter server password
|
|
|
|
Enter password: ...
|
|
|
|
Verify password: ...
|
|
|
...
|
|
...
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
Ausgehend von Hinweisen im Netz, sollte die virtuellen Python-Umgebung auf
|
|
Anmerkung: Es wird der Hash-Code des Passwortes in die Datei `jupyter_server_config.json` im aktuellen Verzeichnis geschrieben.
|
|
|
»Python 3.9« basieren, was die Installation der zugehörigen System-Pakete
|
|
|
|
|
erfordert:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
zypper in python3.11 python3.11-base python3.11-pip
|
|
|
|
|
zypper in pandoc
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Als nächstes wird unterhalb von `/usr/local/share/` die virtuelle Python-Umgebung erzeugt:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
cd /usr/local/share/
|
|
|
|
|
/usr/bin/python3.11 -m venv JupyterLab
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Die eigentliche Installation von »Jupyter Lab« erfordert nun die Aktivierung
|
|
|
|
|
der virtuellen Python-Umgebung (wichtig!):
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
cd JupyterLab
|
|
|
|
|
source ./bin/activate
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Alle nachfolgend zu installierenden Python-Bibliotheken werden nur lokal
|
|
### Erzeugen einer Systemd-Service-Datei
|
|
|
unterhalb des aktuellen Verzeichnisses `/usr/local/share/JupyterLab`
|
|
|
|
|
gespeichert. Voraussetzung für ihre Wirksamkeit ist der activate-Aufruf.
|
|
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
# pip aktualisieren
|
|
|
|
|
python3 -m pip install --upgrade pip
|
|
|
|
|
# Jupyter Lab
|
|
|
|
|
pip3 install jupyterlab
|
|
|
|
|
# Zusätzliche Nutzer-Bibliotheken
|
|
|
|
|
pip3 install matplotlib statistics datetime numpy pandas couchdb
|
|
|
|
|
deactivate
|
|
deactivate
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Um den »Jupyter Lab«-Server automatisch zu starten ist eine Systemd-Service-Datei notwendig. Sie wird folgendermaßen erzeugt:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
cat <<EOF > JupyterLab.service
|
|
cat <<EOF > JupyterLab.service
|
|
|
[Unit]
|
|
[Unit]
|
|
|
Description=JupyterLab Service
|
|
Description=JupyterLab Service
|
| ... | @@ -272,9 +99,10 @@ WorkingDirectory=/usr/local/share/JupyterLab |
... | @@ -272,9 +99,10 @@ WorkingDirectory=/usr/local/share/JupyterLab |
|
|
EnvironmentFile=-/etc/environment
|
|
EnvironmentFile=-/etc/environment
|
|
|
ExecStart=/bin/bash -lc 'source ./bin/activate ; \
|
|
ExecStart=/bin/bash -lc 'source ./bin/activate ; \
|
|
|
jupyter lab --notebook-dir=/home/ipynb/notebooks --no-browser \
|
|
jupyter lab --notebook-dir=/home/ipynb/notebooks --no-browser \
|
|
|
--ServerApp.allow_origin="http://127.0.0.1:82"'
|
|
--config=./jupyter_server_config.json'
|
|
|
User=ipynb
|
|
User=ipynb
|
|
|
Group=ipynb
|
|
Group=ipynb
|
|
|
|
PIDFile=/run/jupyterlab.pid
|
|
|
Restart=on-failure
|
|
Restart=on-failure
|
|
|
RestartSec=60s
|
|
RestartSec=60s
|
|
|
|
|
|
| ... | @@ -284,26 +112,17 @@ WantedBy=multi-user.target |
... | @@ -284,26 +112,17 @@ WantedBy=multi-user.target |
|
|
EOF
|
|
EOF
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
(TODO: Vielleicht kann auf den Apache-Zugang per `http://127.0.0.1:82`
|
|
### Start des Systemd-Services
|
|
|
verzichtet werden durch Verwendung der Parameter `--ip=0.0.0.0 --port=82`;
|
|
|
|
|
testen!)
|
|
|
|
|
|
|
|
|
|
Mit den folgenden Schritten wird die Systemd-Service-Datei installiert und aktiviert sowie der Serverprozess gestartet.
|
|
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
systemctl stop JupyterLab.service
|
|
|
|
|
systemctl link $PWD/JupyterLab.service
|
|
systemctl link $PWD/JupyterLab.service
|
|
|
systemctl daemon-reload
|
|
systemctl daemon-reload
|
|
|
systemctl enable JupyterLab.service
|
|
systemctl enable JupyterLab.service
|
|
|
systemctl start JupyterLab.service
|
|
systemctl start JupyterLab.service
|
|
|
systemctl status JupyterLab.service
|
|
systemctl status JupyterLab.service
|
|
|
#
|
|
|
|
|
chown -R ipynb.ipynb /usr/local/share/JupyterLab
|
|
|
|
|
#
|
|
|
|
|
exit
|
|
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
Sollen später weitere Python-Nutzer-Bibliotheken installiert werden, muss wiederum auf das Aktivieren der virtuellen Python-Umgebung geachtet werden.
|
|
## Spätere Installation weiterer Python-Bibliotheken
|
|
|
|
|
|
|
|
```
|
|
```
|
|
|
ssh root@a73435
|
|
ssh root@a73435
|
| ... | @@ -314,29 +133,7 @@ pip3 install xyz uvw abc |
... | @@ -314,29 +133,7 @@ pip3 install xyz uvw abc |
|
|
deactivate
|
|
deactivate
|
|
|
#
|
|
#
|
|
|
chown -R ipynb.ipynb /usr/local/share/JupyterLab
|
|
chown -R ipynb.ipynb /usr/local/share/JupyterLab
|
|
|
|
systemctl restart JupyterLab.service
|
|
|
#
|
|
#
|
|
|
exit
|
|
exit
|
|
|
``` |
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
=========== 2023-03-30 ==============
|
|
|
|
|
=========== 2023-09-06 ==============
|
|
|
|
|
|
|
|
|
|
Update aller veralteten Komponenten:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
cd /usr/local/share/JupyterLab
|
|
|
|
|
source ./bin/activate
|
|
|
|
|
# Der Fehler "You must give at least one requirement ..." meint,
|
|
|
|
|
# dass keine Updates erforderlich sind.
|
|
|
|
|
pip3 install -U `pip3 list --outdated | awk 'NR>2 {print $1}'`
|
|
|
|
|
chown -R ipynb.ipynb /usr/local/share/JupyterLab
|
|
|
|
|
systemctl restart JupyterLab.service
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|