1,首先,运行下面的命令更新你的 Ubuntu 软件包索引。
sudo apt update
2,现在通过 Ubuntu 软件源安装 Python3 和 Node.js,方法如下--输入 "Y "确认安装:
sudo apt install python3-dev python3-pip python3-venv nodejs npm
python3 --version
pip3 --version
node -v
3,创建一个运行jupyter的用户,最好有sudo权限,有些乱七八糟的东西随便填,密码一定要记住
sudo adduser jupyter //我这里用的是jupyter
给与sudo权限
sudo usermod -aG sudo jupyter
4pip安装jupyter(使用创建的用户 jupyter)
创建一个自定义文件夹并创建虚拟环境
mkdir -p ~/Py; cd ~/Py
python3 -m venv venv
现在用以下命令激活 venv 虚拟环境。激活后,你的 shell 将变成 (venv) user@hostname 的样子。就是前面加了(venv)
source venv/bin/activate
接下来,运行下面的 pip3 命令,通过 PyPi 软件源安装 Jupyter:
pip3 install jupyter
接下来看网速,可能会等一个小时才下完
安装完成后,使用以下命令检查 Jupyter 的版本:
jupyter --version
本节将配置 Jupyter 的两个主要组件,即 jupyter_server 和 jupyterlab。您将为这两个组件生成配置并设置密码验证。然后,通过命令行运行 Jupyter。
首先,运行下面的 jupyter 命令生成 jupyter_server 配置和密码。出现提示时输入密码,然后重复。
jupyter server --generate-config
jupyter server password
用下面的命令检查 jupyter_server 配置。
jupyter server --show-config
接下来,运行下面的 jupyter 命令生成 jupyterlab 配置到 ~/.jupyter/jupyter_lab_config.py。然后,检查 jupyterlab 配置。
jupyter lab --generate-config
jupyter lab --show-config
现在运行下面的 jupyter 命令,从命令行启动 jupyterlab。jupyterlab 应在端口 8889 和 URL 路径 lab 上运行。
jupyter lab --ip=0.0.0.0 --port=8889 --no-browser
访问外部你的服务器ip:端口+你的安装地址
http://services-ip:8889/lab/home/jupyther/py/venv/share/jupyter/lab
现在按 Ctrl+c 键,然后输入 yes 来终止 jupyterlab 进程。
以服务形式运行 JupyterLab
在本指南中,你将在后台以服务形式运行 Jupyter。因此,现在需要为 Jupyter 创建一个新的 systemd 服务文件。
使用下面的 nano 编辑器命令创建新的 systemd 服务文件 /etc/systemd/system/jupyterlab.service。要有sudo权限,没有的看上面
sudo nano /etc/systemd/system/jupyterlab.service
输入以下配置,并确保将用户 jupyther 改为您的用户名。ctrl+x退出,y保存
[Unit]
Description=JupyterLab Service
[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/home/jupyter/Py/venv/bin/jupyter lab --ip=0.0.0.0 --port=8889 --no-browser --config=/home/jupyter/.jupyter/jupyter_lab_config.py
User=jupyter
Group=jupyter
WorkingDirectory=/home/jupyter/Py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
保存文件,完成后退出编辑器。--ip=0.0.0.0 允许外网访问, --port8889指定端口不用8888
现在运行下面的命令重新加载 systemd 管理器并激活新的服务文件。
sudo systemctl daemon-reload
接下来,用下面的命令启动并启用 jupyterlab 服务。
sudo systemctl start jupyterlab
sudo systemctl enable jupyterlab
查看状态
sudo systemctl status jupyterlab和token
重新启动
切换 jupyter用户
/home/jupyter/Py/venv/bin/jupyter-lab --ip=0.0.0.0 --port=8889 --no-browser --config=/home/jupyter/.jupyter/jupyter_lab_config.py