JupyterLabとは
- Jupyter notebookの後継で、いろいろな機能が追加されている
- 参考:https://qiita.com/kirikei/items/a1639954ce5ccaf7ac3c
JupyterLabの課題
- デフォルトではTabを押さないとコード補完(autocomplete)されない
- そのため、いくつかコード補完のextentionが提案されている
- ここでは、jupyterlab-lspについて紹介する
jupyterlab-lspとは
- 開発元のGithub:https://github.com/krassowski/jupyterlab-lsp
- コード補完として、.(ドット)をタイプすると、配下の要素が可視化されるようになる
- なお、jupyterlab-kiteなら、完全自動でコード補完が可能!(こちらの方がおすすめ)
jupyterlab-lspのインストール方法
概要
- 基本的に、開発元のGithubに従ってインストールすれば動作する
- ただし、以下をやらないと動作しないので注意(ハマった)
- "Note on pyls (python-language-server) issues: pyls is known to require specific versions of some dependencies such as ujson <= 1.35, jedi == 0.15.2 and parso == 0.5.2. If you experience any issues with LSP functions in Python, please check if you have the right version using pip freeze command."
- つまり、「ujson」「jedi」「parso」のバージョンを上記にしなければならない。
- バージョンが異なると以下のエラーメッセージが出る。
- ERROR - pyls_jsonrpc.endpoint ...
検証環境
- ubuntu (Windows10 WSL)
- anaconda
- python(3.8)
- jupyterlab(2.1) ※jupyterlab-lspの最新のv1.1.2では、jupyterlab2.2は未対応らしい
- https://github.com/krassowski/jupyterlab-lsp/releases/tag/v1.1.2
インストール方法
conda環境の準備
conda create -n jupyter_test python=3
conda activate jupyter_test
jupyterlab,jupyter-lspのインストール
conda install -c conda-forge jupyterlab=2.1 ujson=1.35 jedi=0.15.2 parso=0.5.2
pip install jupyter-lsp
conda install -c conda-forge nodejs
jupyter labextension install @krassowski/jupyterlab-lsp
conda install -c conda-forge python-language-server r-languageserver
jupyterlabの起動
jupyter lab