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()
可以正常出图了。