Jupyter-Lab
1. 安装Jupyter-lab3.0
1 2 3
| pip install jupyterlab==3
|
2.生成配置文件并设置密码
1 2
| jupyter lab --generate-config jupyter lab password
|
3. 编辑配置文件
1
| vim ~/.jupyter/jupyter_lab_config.py
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| c.ServerApp.allow_origin = '*'
c.ServerApp.allow_remote_access = True
c.ServerApp.ip = '0.0.0.0'
c.ServerApp.root_dir = "/home/username/code"
c.ServerApp.open_browser = False
c.ServerApp.port = 58000
|
4. 安装插件
首先enable插件管理
4.1 安装中文语言包
1
| pip install jupyterlab-language-pack-zh-CN
|
然后在settings→language中切换
4.2 debugger 语法检测
插件Github地址:https://github.com/jupyterlab/debugger
jupyter-lab3.0默认带有debugger,所以不需要额外安装。但缺少依赖包
安装依赖
1 2 3
| conda install -c conda-forge xeus-python
|
4.3 代码提示
插件Github地址:Language Server Protocol integration for Jupyter
安装方法
1 2 3 4 5 6 7
| conda install -c conda-forge jupyterlab-lsp
pip install 'python-lsp-server[all]'
|
4.4 可交互 matplotlib
插件Github地址:ipympl
在代码开头插入即可
安装方法:
1 2 3
| conda install -c conda-forge ipympl
|
4.5 自动代码格式化
插件Github地址:Jupyterlab Code Formatter
配置参考链接:https://blog.csdn.net/mighty13/article/details/120024319
安装方法
1 2
| pip install jupyterlab_code_formatter pip install autopep8
|
重启jupyter lab
设置→高级编辑器
修改jupyterlab Code Formatter
输入内容:
1 2 3 4 5 6 7 8
| { "preferences": { "default_formatter": { "python": "autopep8", "R": "styler" } } }
|
通过点击状态栏或者右键即可使用
5. 添加到开机启动项
1
| sudo vim /etc/systemd/system/jupyter-lab.service
|
输入以下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| [Unit] Description=jupyter lab After=network.target
[Service] Type=simple User=username
ExecStart=/home/marques/.conda/envs/torch-marques/bin/jupyter-lab --no-browser
ExecStop=/usr/bin/pkill jupyter-lab KillMode=process Restart=always RestartSec=30s
[Install] WantedBy=multi-user.target
|
切换虚拟环境启动jupyter-lab脚本
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
| #!/bin/bash -l
__conda_setup="$('/home/dell/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "/home/dell/anaconda3/etc/profile.d/conda.sh" ]; then . "/home/dell/anaconda3/etc/profile.d/conda.sh" else export PATH="/home/dell/anaconda3/bin:$PATH" fi fi unset __conda_setup
conda activate torch-marques
/home/marques/.conda/envs/torch-marques/bin/jupyter-lab --no-browser
|
设置开机启动
1 2 3
| sudo systemctl daemod-relaod sudo systemctl enable jupyter-lab sudo systemctl start jupyter-lab
|
TODO 使用Nignx反代理
挖个坑
参考链接
ubuntu20下anaconda中Jupyterlab3.0配置远程登录
在shell文件中启动anaconda的虚拟环境