GNU/Linux >> Linux Esercitazione >  >> Panels >> Panels

Come installare Jupyter Notebook su Ubuntu 20.04

Jupyter Notebook è uno strumento di sviluppo open source e basato sul Web che consente di creare e condividere codici ed equazioni in tempo reale. È flessibile, estensibile e supporta molti linguaggi di programmazione tra cui Python, Julia, Haskell, Ruby e altri. In genere, viene utilizzato per i dati e l'apprendimento automatico. Viene fornito con il kernel IPython che ti consente di scrivere i tuoi programmi in Python.

In questo post, ti mostreremo come installare Jupyter Notebook su Ubuntu 20.04.

Prerequisiti

  • Un Ubuntu 20.04 VPS (useremo il nostro piano SSD 2 VPS)
  • Accesso all'account utente root (o accesso a un account amministratore con privilegi root)

Accedi al server e aggiorna i pacchetti del sistema operativo del server

Innanzitutto, accedi al tuo server Ubuntu 20.04 tramite SSH come utente root:

ssh root@IP_Address -p Port_number

Una volta effettuato l'accesso, aggiorna i pacchetti di sistema con il seguente comando:

apt-get update -y

Installa le dipendenze richieste

Jupyter Notebook è basato su Python. Quindi dovrai installare Python e altre librerie sul tuo sistema. Puoi installarli tutti con il seguente comando:

apt-get install python3 python3-pip python3-dev -y

Successivamente, verifica la versione installata di Python con il seguente comando:

python3 --version

Uscita:

Python 3.8.5

Quindi, aggiorna il PIP all'ultima versione utilizzando il comando seguente:

pip3 install --upgrade pip

Successivamente, verifica la versione PIP con il seguente comando:

pip3 --version

Uscita:

pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

Quindi, installa il pacchetto Virtual Environment con il seguente comando:

pip3 install virtualenv

Installa Jupyter Notebook

Innanzitutto, crea un utente separato per Jupyter Notebook. Puoi crearlo con il seguente comando:

adduser jupyter

Successivamente, accedi con l'utente Jupyter con il seguente comando:

su - jupyter

Quindi, crea una directory Jupyter e crea un ambiente virtuale per il notebook Jupyter.

mkdir ~/Jupyter
cd ~/Jupyter
virtualenv notebook

Successivamente, attiva l'ambiente virtuale con il seguente comando:

source notebook/bin/activate

Quindi, installa Jupyter con il seguente comando:

(notebook) jupyter@jupyter:~/Jupyter$ pip install jupyter

Una volta installato, esegui il notebook Jupyter con il seguente comando:

(notebook) jupyter@jupyter:~/Jupyter$ jupyter notebook

Dovresti ottenere il seguente output:

[I 06:12:57.527 NotebookApp] Writing notebook server cookie secret to /home/jupyter/.local/share/jupyter/runtime/notebook_cookie_secret
[I 06:12:57.786 NotebookApp] Serving notebooks from local directory: /home/jupyter/Jupyter
[I 06:12:57.786 NotebookApp] Jupyter Notebook 6.3.0 is running at:
[I 06:12:57.787 NotebookApp] http://localhost:8888/?token=9a7e565bbe40a36e7afbcd9cda890823288c61312e9f1eed
[I 06:12:57.787 NotebookApp]  or http://127.0.0.1:8888/?token=9a7e565bbe40a36e7afbcd9cda890823288c61312e9f1eed
[I 06:12:57.787 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 06:12:57.791 NotebookApp] No web browser found: could not locate runnable browser.
[C 06:12:57.791 NotebookApp] 

    To access the notebook, open this file in a browser:
        file:///home/jupyter/.local/share/jupyter/runtime/nbserver-11919-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=9a7e565bbe40a36e7afbcd9cda890823288c61312e9f1eed
     or http://127.0.0.1:8888/?token=9a7e565bbe40a36e7afbcd9cda890823288c61312e9f1eed

Premi CTRL+C per interrompere Jupyter Notebook.

Successivamente, dovrai generare un file di configurazione per Jupyter Notebook. Puoi generarlo con il seguente comando:

(notebook) jupyter@jupyter:~/Jupyter$ jupyter notebook --generate-config

Dovresti ottenere il seguente output:

Writing default config to: /home/jupyter/.jupyter/jupyter_notebook_config.py

Quindi, imposta la password per Jupyter con il seguente comando:

(notebook) jupyter@jupyter:~/Jupyter$ jupyter notebook password

Dovresti vedere il seguente output:

Enter password: 
Verify password: 
[NotebookPasswordApp] Wrote hashed password to /home/jupyter/.jupyter/jupyter_notebook_config.json

Successivamente, disattiva dall'ambiente virtuale Python con il seguente comando:

(notebook) jupyter@jupyter:~/Jupyter$ deactivate

Quindi, disconnettersi dall'utente Jupyter con il seguente comando:

exit

Crea un file di servizio Systemd per Jupyter

Successivamente, dovrai creare un file di servizio systemd per gestire Jupyter Notebook. Puoi crearlo con il seguente comando:

nano /etc/systemd/system/jupyter.service

Aggiungi le seguenti righe:

[Unit]
Description=Jupyter Notebook

[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/home/jupyter/Jupyter/notebook/bin/jupyter-notebook --config=/home/jupyter/.jupyter/jupyter_notebook_config.py
User=jupyter
Group=jupyter
WorkingDirectory=/home/jupyter/Jupyter/notebook
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Salva e chiudi il file, quindi ricarica il demone systemd con il seguente comando:

systemctl daemon-reload

Quindi, avvia il servizio Jupyter e abilitalo all'avvio al riavvio del sistema con il seguente comando:

systemctl start jupyter
systemctl enable jupyter

Puoi anche verificare lo stato di Jupyter con il seguente comando:

systemctl status jupyter

Uscita:

● jupyter.service - Jupyter Notebook
     Loaded: loaded (/etc/systemd/system/jupyter.service; disabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-04-06 06:32:47 UTC; 2min 33s ago
   Main PID: 14630 (jupyter-noteboo)
      Tasks: 1 (limit: 2353)
     Memory: 40.6M
     CGroup: /system.slice/jupyter.service
             └─14630 /home/jupyter/Jupyter/notebook/bin/python /home/jupyter/Jupyter/notebook/bin/jupyter-notebook --config=/home/jupyter/.jup>

Apr 06 06:32:47 jupyter systemd[1]: Started Jupyter Notebook.
Apr 06 06:32:48 jupyter jupyter-notebook[14630]: [I 06:32:48.023 NotebookApp] Serving notebooks from local directory: /home/jupyter/Jupyter/no>
Apr 06 06:32:48 jupyter jupyter-notebook[14630]: [I 06:32:48.024 NotebookApp] Jupyter Notebook 6.3.0 is running at:
Apr 06 06:32:48 jupyter jupyter-notebook[14630]: [I 06:32:48.024 NotebookApp] http://localhost:8888/
Apr 06 06:32:48 jupyter jupyter-notebook[14630]: [I 06:32:48.024 NotebookApp] Use Control-C to stop this server and shut down all kernels (twi>
Apr 06 06:32:48 jupyter jupyter-notebook[14630]: [W 06:32:48.030 NotebookApp] No web browser found: could not locate runnable browser.

Configura Nginx come proxy inverso per Jupyter Notebook

Successivamente, dovrai configurare Nginx come proxy inverso per Jupyter Notebook.

Innanzitutto, installa Nginx con il seguente comando:

apt-get install nginx -y

Una volta installato, crea un file di configurazione dell'host virtuale Nginx con il seguente comando:

nano /etc/nginx/conf.d/jupyter.conf

Aggiungi le seguenti righe:

upstream jupyter {
server 127.0.0.1:8888;
}

server {
listen 80;
server_name jupyter.example.com;

access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;

location / {
     proxy_pass http://localhost:8888;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header Host $http_host;
     proxy_http_version 1.1;
     proxy_redirect off;
     proxy_buffering off;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "upgrade";
     proxy_read_timeout 86400;
     }
}

Salva e chiudi il file, quindi verifica Nginx con il seguente comando:

nginx -t

Uscita:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Quindi, riavvia Nginx per applicare le modifiche:

systemctl restart nginx

Successivamente, aggiungi l'utente Jupyter al gruppo www-data con il seguente comando:

usermode -g www-data jupyter

Quindi, modifica il file di configurazione di Jupyter Notebook e consenti l'accesso remoto.

nano /home/jupyter/Jupyter/.jupyter/jupyter_notebook_config.py

Modifica la seguente riga:

c.NotebookApp.allow_remote_access = True

Salva e chiudi il file, quindi riavvia il servizio Jupyter per applicare le modifiche:

systemctl restart jupyter

Accedi a Jupyter Notebook

Ora apri il tuo browser web e accedi a Jupyter Notebook utilizzando l'URL http://jupyter.example.com . Ti verrà chiesto di fornire una password come mostrato di seguito:

Fornisci la tua password e fai clic su Accedi pulsante. Dovresti vedere la dashboard di Jupyter Notebook nella schermata seguente:

Congratulazioni! hai installato con successo Jupyter Notebook su Ubuntu 20.04 VPS.

Ora che sai come installare Jupyter Notebook su Ubuntu 20.04, puoi vedere come il nostro hosting VPS Linux gestito può essere facile e conveniente. Non hai davvero bisogno di installare tu stesso Jupyter Notebook su Ubuntu, chiedi semplicemente a uno dei nostri amministratori di sistema di installarlo per te, completamente gratuito. Sono disponibili 24 ore su 24, 7 giorni su 7, 365 giorni l'anno e sono pronti ad aiutarti in qualsiasi aspetto della gestione del tuo server.


Panels
  1. Come installare ISPConfig 3 su Ubuntu 18.04

  2. Come installare Webmin su Ubuntu 18.04

  3. Come installare R su Ubuntu 16.04

  4. Come installare Jupyter su Ubuntu 18.04

  5. Come installare Vai su Ubuntu 18.04

Come installare Jupyter Notebook su Ubuntu 22.04 | 20.04

Come installare Jupyter su Ubuntu 18.04 LTS

Come installare Jupyter Notebook su Ubuntu 20.04 LTS

Come installare Go in Ubuntu 20.04

Come installare il notebook Jupyter su Ubuntu 22.04

Come installare Vai su Ubuntu 22.04