Jupyter Lab 进阶安装教程

诏谓将军指绢素,意匠惨淡经营中。

——《丹青引赠曹将军霸》唐/杜甫

记录安装Jupyter Lab,配置插件,配置远程访问的过程。

安装tljh

1
2
sudo apt install python3 python3-dev git curl
curl -L https://tljh.jupyter.org/bootstrap.py | sudo -E python3 - --admin feng

升级Upgrade to a newer Python version

1
2
3
4
5
source /opt/tljh/user/bin/activate
pip freeze > pip_pkgs.txt
sudo PATH=${PATH} conda update --all
sudo PATH=${PATH} conda install python=3.x
pip install -r pip_pkgs.txt

删除tljh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
sudo rm -rf /opt/tljh/hub
sudo rm -rf /opt/tljh/user
sudo unlink /usr/bin/tljh-config
sudo rm -rf /opt/tljh/config
sudo systemctl stop jupyterhub.service
sudo systemctl stop traefik.service
sudo systemctl stop jupyter-feng
# disable the services
sudo systemctl disable jupyterhub.service
sudo systemctl disable traefik.service
# run this command for all the Jupyter users
sudo systemctl disable jupyter-feng
# remove the systemd unit
sudo rm /etc/systemd/system/jupyterhub.service
sudo rm /etc/systemd/system/traefik.service
# reset the state of all units
sudo systemctl daemon-reload
sudo systemctl reset-failed
sudo rm -rf /opt/tljh/state
sudo rm /var/run/index.html
sudo rm /var/run/favicon.ico
sudo userdel -r jupyter-feng
sudo delgroup jupyterhub-users
sudo delgroup jupyterhub-admins
# remove jupyterhub-admins from the sudoers group
sudo rm /etc/sudoers.d/jupyterhub-admins
sudo rm -rf /opt/tljh

查看 ubuntu 所有用户

1
cat /etc/passwd|grep -v nologin|grep -v halt|grep -v shutdown|awk -F":" '{ print $1"|"$3"|"$4 }'|more

安装cuda11.0

1
2
3
4
5
6
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
sudo apt-get update
sudo apt-get -y install cuda-11-0

安装cudnn

1
2
3
4
5
6
7
/sbin/ldconfig.real: /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_ops_train.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8 is not a symbolic link
/sbin/ldconfig.real: /usr/local/cuda-11.0/targets/x86_64-linux/lib/libcudnn_adv_train.so.8 is not a symbolic link

遇见以上问题的解决方法:

1
2
3
4
tar -xzvf ./cudnn-*.tgz
sudo cp -d cuda/include/cudnn*.h /usr/local/cuda/include
sudo cp -d cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*

JupyterLab common use

JupyterLab 和一些 Machine Learning 常用的软件包

1
2
3
4
pip install --no-cache jupyterlab ipywidgets pandas openpyxl  sweetviz rich pretty_errors 
pip install --no-cache torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
pip install --no-cache 'ray[tune]' xgboost pytorch-lightning scikit-learn
# python -m pretty_errors
1
2
3
4
5
6
7
8
# 前置条件 -> 系统安装 `nodejs` 和当前 python 环境下安装 `npm`
pip install npm
pip install jupyterlab_latex bokeh jupyter_bokeh
jupyter labextension install @jupyterlab/toc
jupyter labextension install @jupyterlab/latex
jupyter labextension install @mflevine/jupyterlab_html
jupyter labextension install @jupyter-widgets/jupyterlab-manager
jupyter labextension install @bokeh/jupyter_bokeh

JupyterLab 中文语言包 安装 jupyterlab-language-pack-zh-CN

Kite 安装及JupyterLab设置

1
2
3
4
sudo apt install xdg-utils
bash -c "$(wget -q -O - https://linux.kite.com/dls/linux/current)"
~/.local/share/kite/login-user
pip install "jupyterlab-kite>=2.0.2"

Kite 卸载

1
~/.local/share/kite/uninstall && rm -rf ~/.kite

安装字体

linux系统的字体文件放在/usr/share/fonts/目录以及用户的/.fonts和/.local/share/fonts目录下,第一个位置为系统所用用户共享,将字体安装到这个目录需要管理员权限;后面两个位置则为当前登陆用户所有,安装字体到这个目录不需要管理员权限。

安装到 /usr/share/fonts/

1
2
3
4
5
6
7
8
9
10
11
# 下载xxx字体
wget https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf
sudo mkdir -p /usr/share/fonts/custom
sudo mv ./*.ttf /usr/share/fonts/custom
sudo chmod 744 /usr/share/fonts/custom/*.ttf
# 安装和生成字体缓存
cd /usr/share/fonts/custom
#生成核心字体信息
sudo mkfontscale
sudo mkfontdir
sudo fc-cache -fv