1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > Ubuntu20.04云服务器安装配置Jupyter Lab

Ubuntu20.04云服务器安装配置Jupyter Lab

时间:2022-02-28 17:37:55

相关推荐

Ubuntu20.04云服务器安装配置Jupyter Lab

❚ 前言

Jupyter LabJupyter主打的最新数据科学生产工具,是基于Web的交互式开发环境。某种意义上,它的出现是为了取代Jupyter Notebook,但它也包含了Jupyter Notebook的所有功能,非常方便研究和教学。Jupyter Lab的用途非常灵活,可支持数据清理和转换、统计建模、数据科学、科学计算和机器学习领域的广泛工作。

❚ 安装 Jupyter Lab

1. 云服务器环境

▸ CPU:2核   内存:2GB

▸ 系统盘:40GB SSD云硬盘

▸ 操作系统:Ubuntu Server 20.04 LTS 64bit

▸ Python版本: 3.9.13   pip版本:22.1.2

❚ 注:安装Jupyter Lab前需要安装Python(3.3版本及以上,或2.7版本)和pip

2. 安装 Miniconda

❚ 更新升级已安装的软件包至最新版本

su// 切换到 root 用户apt update && apt upgrade

❚ 以下操作不推荐使用root用户

su ubuntu // 切换到 ubuntu 用户cd // 切换到 /home/ubuntu/

❚ 安装Miniconda(清华源)

wget https://mirrors.tuna./anaconda/miniconda/Miniconda3-py39_4.12.0-Linux-x86_64.shbash Miniconda3-py39_4.12.0-Linux-x86_64.shsource ~/.bashrcconda --v

❚ 切换conda源为清华源(可选)

vim ~/.condarc

condarc文件中添加以下内容

channels:- defaultsshow_channel_urls: truechannel_alias: https://mirrors.tuna./anacondadefault_channels:- https://mirrors.tuna./anaconda/pkgs/main- https://mirrors.tuna./anaconda/pkgs/free- https://mirrors.tuna./anaconda/pkgs/r- https://mirrors.tuna./anaconda/pkgs/pro- https://mirrors.tuna./anaconda/pkgs/msys2custom_channels:conda-forge: https://mirrors.tuna./anaconda/cloudmsys2: https://mirrors.tuna./anaconda/cloudbioconda: https://mirrors.tuna./anaconda/cloudmenpo: https://mirrors.tuna./anaconda/cloudpytorch: https://mirrors.tuna./anaconda/cloudsimpleitk: https://mirrors.tuna./anaconda/cloud

❚ 清除索引缓存

conda clean -i

3. 安装 Jupyter Lab

conda install jupyterlab

❚ 准备Jupyter Lab密码

python// 进入 Python 环境> from notebook.auth import passwd> passwd() # 输入自己想要设置的密码(重复)得到类似 'argon2:...'的加密串,保存备用'argon2:$argon2id$v=19$m=10240,t=10,p=8$tuOUUSE/KyCKtjW6HmLLvg$WJWRe2O/TDJheuzPcWebZcXkSe8aoW8hsZQrKAyeGxQ'> quit() # 退出 Python 环境

4. 配置 Jupyter Lab 端口访问

jupyter lab --generate-config // 创建配置文件cd ~/.jupytervim jupyter_lab_config.py // 编辑配置文件

根据自己需求更新以下内容

c.ServerApp.allow_origin = '*'// 约 576 行c.ServerApp.allow_remote_access = True // 约 614 行c.ServerApp.ip = '0.0.0.0' // 默认是 localhost 约 775 行c.ServerApp.notebook_dir = '/home/ubuntu/workspace' // 项目文件夹 约 868 行c.ServerApp.password = 'xxxxxx' // 刚生成的类似 'argon2:...' 的加密串 约 887 行c.ServerApp.open_browser = False // 禁止浏览器打开 约 876 行c.ServerApp.port = 8080 // 端口 随自己选择即可 约 900 行

❚ 注:部署在云服务器需要检查是否在防火墙(安全组)开放你配置的端口

5. 运行 Jupyter Lab

jupyter lab

❚ 注:若选择IP直连,且已在防火墙开放对应端口,即可使用IP:8888(端口)访问

6. 开启插件管理器

conda install -c conda-forge jupyter_contrib_nbextensions

❚ 注:安装完成后再次运行Jupyter Lab将会有GUI,此处不再赘述

7. 设置中文(简体)语言

pip install jupyterlab-language-pack-zh-CN

❚ 注:安装完成后再次运行Jupyter Lab需要在菜单栏选择【设置】→ 【语言】→ 【中文(简体,中国)】,将会自动重载页面,配置完成!

8. 安装 Nodejs(安装插件需要)

conda install -c conda-forge/label/cf20 nodejs

9. 添加 Julia 编程语言(可选)

❚ 获取 Julia 编程语言压缩包并解压

wget https://mirrors.tuna./julia-releases/bin/linux/x64/1.8/julia-1.8-latest-linux-x86_64.tar.gztar -xzvf julia-1.8-latest-linux-x86_64.tar.gz

❚ 配置Julia环境

vim ~/.bashrc

在文件末尾添加以下内容

export PATH=$PATH:/home/ubuntu/julia-1.8.0-rc4/bin // 添加环境变量export JULIA_PKG_SERVER=https://mirrors.tuna./julia // 添加清华源为 Julia 包源

❚ 立刻加载更新后的设置,使之生效

source ~/.bashrc

❚ 配置 Jupyter 内核

julia// 进入 Julia 环境julia> using Pkgjulia> Pkg.add("IJulia") julia> exit()// 退出 Julia 环境

10. 配置 C/C++ 内核(可选)

❚ 安装C++内核

mamba install xeus-cling -c conda-forge

❚ 安装C内核

pip install jupyter-c-kernelinstall_c_kernel --user

11. 安装 Python 数据科学/机器学习常用库

conda install pytorch torchvision torchaudio cpuonly -c pytorchpip install numpy conda pandas scipy matplotlibpip install joblibpip install -U scikit-learnpip install simplejsonpip install networks networkxpip install opencv-pythonpip install opencv-contrib-python opencv-python-headlesspip install Seabornpip install Keras

12. 配置 Jupyter Lab 开机自启动(方法1 可选)

❚ 新建jupyter.service文件并编辑

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

添加以下内容(以自己的配置为准)

[Unit]Description=JupyterlabAfter=network.target[Service]Type=simpleExecStart=/home/ubuntu/miniconda3/bin/jupyter-lab --config=/home/ubuntu/.jupyter/jupyter_lab_config.py --no-browserUser=ubuntuGroup=ubuntuWorkingDirectory=/home/ubuntu/workspaceRestart=alwaysRestartSec=10[Install]WantedBy=multi-user.target

❚ 设置开机自启动

sudo systemctl enable jupyter

❚ 其他相关控制命令

sudo systemctl start jupyter (启动)sudo systemctl stop jupyter (停止)sudo systemctl restart jupyter (重启)

❚ 该方法存在启动后扩展管理器错误问题(如下所示):

与服务器扩展通信出错。请参考文档 以确保它已启用。 原因: Error: 500 (Internal Server Error)

❚ 注:该错误仅对插件管理器的网络连接有影响,不影响Jupyter Lab的正常使用!

13. 配置 Jupyter Lab 后台启动不挂断(方法2 可选)

❚ 新建jupyter-start.sh文件并编辑

vim jupyter-start.sh

添加以下内容(以自己的配置为准)

#!/bin/sh/bin/echo $(/bin/date +%F_%T) >> /home/ubuntu/startup.lognohup /home/ubuntu/miniconda3/bin/jupyter-lab --allow-root > jupyter.log 2>&1 &ps -le | grep jupyterexit 0

❚ 启动 Jupyter Lab (关闭终端不挂断)

bash jupyter-start.sh

❚ 注:该方法尚无法实现服务器重启后自动运行,需要手动启动!

❚ 运行效果展示

❚ 注:本教程尚未讲解插件安装过程 ,以下为我已安装的插件,仅供参考!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。