3
3

More than 1 year has passed since last update.

Jupyter Labとipywidgets install 備忘録

Posted at

概要

ipywidgetsが使われているnotebookがJupyter labで正常に表示されなかったので、conda仮想環境作成時に忘れないように残す。
Colabは予め環境が出来ているので何もしなくとも問題ない。

  • 実施期間: 2022年1月
  • 環境:Python3.8.12 (miniconda)
  • OS: Ubuntu20.04 LTS

現象

いつもversion指定なしにJupyter labをインストールしている。

conda install -c conda-forge jupyterlab

2022/1現在、指定しなければver.2.1.0が入る。
ver.2でipywidgetsを表示させるため下記を行った。

conda install -c conda-forge ipywidgets
conda install -c conda-forge ipympl
conda install -c conda-forge nodejs
conda install -n base -c conda-forge jupyterlab_widgets
jupyter nbextension enable --py widgetsnbextension
jupyter labextension install @jupyter-widgets/jupyterlab-manager

最後のjupyter labextensionコマンドで次のエラーが発生し先に進めなかった。

ValueError: Please install nodejs >=10.0.0 before continuing.

このときのnodejsは6.13.1だった。

やったこと

これ以上、環境をいじりたくなかったので別の仮想環境を作成しipywidgetsが動作することを確認した。
まっさらの環境で実行したコマンドは下記
Jupyter labは明示的にver.3を指定する。

conda install -c conda-forge matplotlib
conda install -c conda-forge jupyterlab=3
conda install -c conda-forge ipywidgets
conda install -c conda-forge ipympl

これで正常に動作したコードが下記

uploader = widgets.FileUpload(accept='.csv', description='Select csv file')
display(uploader)

separator = widgets.Dropdown(options=[('Tabulator', '\t'), ('Comma',','), ('Semicolon', ';')],
                             value='\t',
                             description='Separator:',
                             disabled=False)
display(separator)

Screenshot from 2022-01-04 15-45-15.png

正常に動作したのはver.2で実施したbaseに対するこのコマンドが効いている可能性もある。

conda install -n base -c conda-forge jupyterlab_widgets

また、サイトによってはセルの冒頭に下記を書く必要があると書かれているが、なくてもipymplの描画は可能だった。

%matplotlib widget

参考
https://ipywidgets.readthedocs.io/en/stable/user_install.html

以上

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3