JupyterLab¶
1. 安装 Python 及 pip¶
apt update
apt install python3 python3-pip -y
2. 安装 Jupyter Lab¶
mkdir -p /data/python3/venv
# 使用 Python 3 的虛擬環境模組創建一個新的虛擬環境
python3 -m venv /data/python3/venv
# 激活指定的虛擬環境,使其成為當前 shell 的 Python 環境
source /data/python3/venv/bin/activate
pip3 install jupyterlab
# 退出虛擬環境
deactivate
3. 生成和配置 Jupyter¶
# 生成配置文件
jupyter lab --generate-config
配置文件位置如:~/.jupyter/jupyter_lab_config.py
# 设置访问密码
jupyter lab password
# 编辑配置文件(允许远程访问)
nano ~/.jupyter/jupyter_lab_config.py
# 将以下行取消注释并设置:
c.ServerApp.ip = '127.0.0.1' # 0.0.0.0允许任意主机访问
c.ServerApp.open_browser = False # 不自动打开本地浏览器
c.ServerApp.port = 8888 # (可选)指定端口
4. 启动 Jupyter Lab¶
jupyter lab --ip=127.0.0.1 --port=8888 --no-browser
# 如果你是直接使用root帳號
jupyter lab --ip=127.0.0.1 --port=8888 --no-browser --allow-root
5. Docker 安装(可选方案)¶
apt install docker.io -y
docker pull jupyter/datascience-notebook
docker run -d --name jupyterlab -p 8888:8888 -v ~/yourdir:/home/jovyan/work jupyter/datascience-notebook
6. 配置systemctl¶
nano /etc/systemd/system/jupyterlab.service
[Unit]
Description=Jupyter Lab
After=network.target
[Service]
Type=simple
User=root
Group=root
WorkingDirectory=/root
ExecStart=/data/python3/venv/bin/jupyter lab --ip=127.0.0.1 --port=8888 --no-browser --allow-root
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
常用命令
systemctl daemon-reload
systemctl enable jupyterlab
systemctl start jupyterlab
systemctl status jupyterlab
systemctl stop jupyterlab
systemctl restart jupyterlab
# 查看運行日誌
journalctl -u jupyterlab -f
7. 安裝插件¶
# Python 遠端調試工具
pip3 install ptvsd
# 將 C++ 開發的 xeus engine 與 Python 結合
pip3 install xeus-python
# 程式碼自動格式化的功能
pip3 install jupyterlab_code_formatter
# 直接進行 Git 操作(如版本控制、提交、回溯等)
pip3 install jupyterlab-git
# 能插入互動式元件(滑桿、下拉選單等)
pip3 install ipywidgets
# 內嵌 Draw.io 圖形編輯器,可創建流程圖、組織圖、架構圖等視覺化內容
pip3 install jupyterlab-drawio
# 提供變數總覽視窗,類似於 MATLAB/SPYDER 的變數檢視,可直觀看到目前工作空間所有變數與型態
pip3 install lckr-jupyterlab-variableinspector
# 建立與預覽 LaTeX 文件
pip3 install jupyterlab-latex
# 帶來程式碼自動補全、即時語法檢查等先進開發功能
pip3 install jupyter-lsp