How to install jupyter notebook on ubuntu 20.04

作者: shaneZhang 分类: 未分类 发布时间: 2021-05-19 19:21

Base environment:

➜  ~ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal
➜  ~ python --version
Python 3.8.5
➜  ~ pip --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
➜  ~ nginx -v
nginx version: nginx/1.18.0 (Ubuntu)

Installing Jupyter

pip install jupyter

jupyter jupyter notebook --generate-config
vim /home/zhangyuqing/.jupyter/jupyter_notebook_config.py

add the hostname of nginx
# allow requests from your domain (works in combo with $http_host from NGINX)
c.NotebookApp.local_hostnames = ['localhost','jupyter.n5.box']
change the http port
c.NotebookApp.port = 7788

Systemd Service

sudo vim /lib/systemd/system/jupyter.service

[Unit] 
Description=Jupyter Management 
After=network.target  
 
[Service]
User=zhangyuqing
Group=zhangyuqing
WorkDirectory=/home/notebook/
ExecStart=/usr/local/bin/jupyter notebook  
Restart=on-failure 
RestartSec=10

[Install] 
WantedBy=multi-user.target
sudo systemctl daemon-reload 
sudo systemctl enable jupyter.service
sudo systemctl start jupyter.service
sudo systemctl status jupyter.service

Nginx Settings

sudo vim /etc/nginx/sites-enabled/jupyter
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 80;
    listen [::]:80;
    server_name jupyter.n5.box;
    location / {
        proxy_pass http://localhost:7788;
        proxy_set_header Host $http_host;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}
sudo systemctl restart nginx.service

Jupyter Password

jupyter notebook password

本页面支持繁体中文友好显示:How to install jupyter notebook on ubuntu 20.04

如果觉得我的文章对您有用,请随意打赏。如果有其他问题请联系博主QQ(909491009)或者下方留言!

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

标签云