pip install jupyterlab==3
# 或者使用conda安装
# conda install -c conda-forge jupyterlab=3
jupyter lab --generate-config
jupyter lab password
vim ~/.jupyter/jupyter_lab_config.py
# 允许跨域访问,在用nginx反向代理jupyter-lab时需要打开
c.ServerApp.allow_origin = '*'
# 允许远程访问
c.ServerApp.allow_remote_access = True
# 监听来自所有ip的连接,默认时localhost只能本地访问
# 假设主机局域网ip为192.168.1.101,此处设置为局域网ip,则局域网内都可以访问
c.ServerApp.ip = '0.0.0.0'
# 设置默认打开路径
c.ServerApp.root_dir = "/home/username/code"
# 开启jupyter-lab时不自动打开浏览器
c.ServerApp.open_browser = False
# 默认监听端口
c.ServerApp.port = 58000
首先enable插件管理
pip install jupyterlab-language-pack-zh-CN
然后在settings→language中切换
插件Github地址:https://github.com/jupyterlab/debugger
jupyter-lab3.0默认带有debugger,所以不需要额外安装。但缺少依赖包
安装依赖
conda install -c conda-forge xeus-python
# 或者
# pip install xeus-python
插件Github地址:Language Server Protocol integration for Jupyter
安装方法
# 先安装Language Server Protocol integration for Jupyter-lab
conda install -c conda-forge jupyterlab-lsp
# 或者
#pip install jupyterlab-lsp
# 再安装语法库
pip install 'python-lsp-server[all]'
插件Github地址:ipympl
在代码开头插入即可
%matplotlib widget
安装方法:
conda install -c conda-forge ipympl
# 或者
# pip install ipympl
插件Github地址:Jupyterlab Code Formatter
配置参考链接:https://blog.csdn.net/mighty13/article/details/120024319
安装方法
pip install jupyterlab_code_formatter
pip install autopep8
重启jupyter lab
设置→高级编辑器
修改jupyterlab Code Formatter
输入内容:
{
"preferences": {
"default_formatter": {
"python": "autopep8",
"R": "styler"
}
}
}
通过点击状态栏或者右键即可使用
sudo vim /etc/systemd/system/jupyter-lab.service
输入以下内容
[Unit]
Description=jupyter lab
After=network.target # 在网络启动后启动此服务
[Service]
Type=simple
User=username # 以此用户启动本程序
# 启动脚本
ExecStart=/home/marques/.conda/envs/torch-marques/bin/jupyter-lab --no-browser # jupyter-lab路径
# 因为我使用anaonda默认虚拟环境启动,所以选择执行脚本方式启动
# ExecStart=/home/marques/software/jupyterlabscript/lab.sh
ExecStop=/usr/bin/pkill jupyter-lab
KillMode=process
Restart=always # 程序崩溃后自动重启程序
RestartSec=30s # 当程序崩溃后30s重新启动
[Install]
WantedBy=multi-user.target
切换虚拟环境启动jupyter-lab脚本
#!/bin/bash -l
# 上面 -l 参数是指以会话方式打开脚本,否则无法切换anaconda虚拟环境
# 下面这段在~/.bashrc复制过来
# 其操作是将conda添加到环境变量
# 每台服务器安装位置不一定一致,要重新复制
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__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 initialize <<<
# 切换虚拟环境
conda activate torch-marques
# 启动jupyter-lab
/home/marques/.conda/envs/torch-marques/bin/jupyter-lab --no-browser
设置开机启动
sudo systemctl daemod-relaod
sudo systemctl enable jupyter-lab
sudo systemctl start jupyter-lab
挖个坑
ubuntu20下anaconda中Jupyterlab3.0配置远程登录
在shell文件中启动anaconda的虚拟环境