13

开启 JupyterLab 代码自动提示功能

 2 years ago
source link: https://xujinzh.github.io/2023/02/10/jupyterlab-code-completion/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

开启 JupyterLab 代码自动提示功能

2023-02-10technologypython

3 1k 1 分钟

JupyterLab 不仅能够书写代码而且也非常方便书写说明内容以及 LATEX 代码,另外,它支持多种编程语言。在 Pycharm 中集成了自动代码提示,文件跳转等,在 JupyterLab 中也可以实现。本篇对其进行介绍。

安装基本包

pip install jupyterlab-lsp
pip install 'python-lsp-server[all]'
# 也可采用方法:进入 JupyterLab,点击扩展,搜索 @krassowski/jupyterlab-lsp 点击安装即可。
jupyter labextension install @krassowski/jupyterlab-lsp

重启 jupyterlab

# 我这里是 jupyterhub
sudo systemctl restart jupyterhub.service

重启后已经可以使用代码提示了。但需要注意两点:

  1. 代码提示需要 tab 键配合。后面设置如何自动提示;
  2. 代码跳转个人编写的包正常,conda 和 pip 安装的包不能成功。后面进行配置。

代码自动提示设置

进入 JupyterLab, 点击设置–高级设置–Code Completion–勾选 Continuous hinting

代码跳转设置

进入 jupyter 根目录(可在 JupyterLab 文件夹选择根文件夹查看),我这里是当前用户目录,设置如下:

cd ~
ln -s / .lsp_symlink

由于此符号链接是一个隐藏文件,因此必须指示 Jupyter 服务器提供隐藏文件。使用适当的命令行标志:

jupyter lab --ContentsManager.allow_hidden=True

或者把该设置在配置文件(jupyter_server_config.py)中进行,如果没有配置文件,可以用如下命令生成:

# 生成配置文件
jupyter server --generate-config

然后进入配置文件把 c.ContentsManager.allow_hidden = True 打开
最后重启 JupyterLab 即可。

参考文献:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK