1、安裝JupyterLab
pip install jupyterlab
2、安裝ipython
pip install ipython
3、設置JupyterLab密碼
# 進入ipython交互環境
(utils) D:\python_env\utils\jupyter> ipython Python 3.7.11 (default, Jul 27 2021, 09:42:29) [MSC v.1916 64 bit (AMD64)] Type 'copyright', 'credits' or 'license' for more information IPython 7.29.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: from notebook.auth import passwd In [2]: passwd() Enter password: Verify password: Out[2]: 'argon2:$argon2id$v=19$m=10240,t=10,p=8$uFb8xsJB19Bw62UZ3mf/YA$AIbk9gFc5hwLvf97MdYODA'
# 創建JupyterLab 配置文件
jupyter lab --generate-config
生成jupyterLab的配置文件:/root/.jupyter/jupyter_lab_config.py
# 修改配置文件中的以下配置
c.ServerApp.allow_root = True c.ServerApp.open_browser = False c.ServerApp.password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$uFb8xsJB19Bw62UZ3mf/YA$AIbk9gFc5hwLvf97MdYODA'
# 登錄JupyterLab進行驗證。
nohup jupyter-lab &
如果登錄驗證密碼出錯,可以在命令行直接更新密碼:
[root@test ipynb]# jupyter-lab password Enter password: Verify password: [JupyterPasswordApp] Wrote hashed password to /root/.jupyter/jupyter_server_config.json
重啟jupyterlab,再用新密碼進行驗證。
4、安裝中文語言
pip install jupyterlab-language-pack-zh-CN
登錄JupyterLab,在菜單里選擇 “設置” -> "語言“ ,選擇 ”中文語言“。
5、配置JupyterLab使用虛擬環境
Jupyter Notebook和JupyterLab相同的配置。
# 安裝ipykernel:
(base) [root]# conda activate dl (dl) [root]# conda install nb_conda_kernels Collecting package metadata (current_repodata.json): done Solving environment: done
# 激活conda環境:conda activate 環境名稱,將環境寫入notebook的kernel中
python -m ipykernel install --user --name 環境名稱 --display-name "顯示的名稱"
如下:
(dl) [root]# python -m ipykernel install --user --name dl --display-name dl Installed kernelspec dl in /root/.local/share/jupyter/kernels/dl
# 打開jupyterlab
瀏覽器打開對應地址,就會有對應的環境提示了
打開Notebook后,可以選擇使用哪個kernel。
6、JupyterLab Git
在插件搜索欄中輸入git,點擊安裝,出現下面提示內容:
# pip install jupyterlab-git
安裝完成后,點擊確定按鈕,重啟jupyterlab。
Jupyterlab使用plotly圖片不顯示解決方法
問題
anaconda裝好了plotly庫,進入lab畫圖,發現不管怎樣都顯示空白,無法顯示圖片。
解決方法
這是因為沒有安裝渲染支持的插件。
在命令行輸入:
#首先需要安裝nodejs12.0.0以上版本
conda install nodejs
#接下來安裝渲染插件
jupyter labextension install jupyterlab-plotly@4.14.3
跑一下示例代碼:
import plotly.graph_objects as go fig = go.Figure(data=go.Bar(y=[2, 3, 1])) fig.show()
可以正常出圖了。