LoginSignup
8
9

More than 3 years have passed since last update.

jupyterLab で tqdm を用いたプログレスバーの表示が上手くできなかったのでその備忘録

Posted at

はじめに

へ~プログレスバーの表示がtqdmってライブラリで簡単にできるのか~!
表示できんやんけ!となったので解決した方法をまとめておきます.

実装環境

  • Windows10
  • Anaconda3
  • Python3
  • juyterLab2.2.6

tqdmのinstallと実装

pip install tqdm

Anacondaの人は以下で,私は最初から入ってたのでinstall不要でした

conda install tqdm

さっそく実装

tqdm.py
import pandas as pd
import numpy as np
import tqdm
import time

for i in tqdm(range(10)):
  time.sleep(1)

しかし出力は以下のHBoxなんとかかんとかというテキスト

HBox(children=(IntProgress(value=0, max=10), HTML(value='')))

そういえばJupyter notebookではnotebook用のメソッドを使う必要があったっけ?と思い以下に変更.

tqdm.py
import pandas as pd
import numpy as np
from tqdm.notebook import tqdm
import time

for i in tqdm(range(10)):
  time.sleep(1)

しかし結果変わらずテキストを出力.
これは困ったので解決策を検索

解決策

どうやら以下の三つを実行しないと初期状態のnotebookでは表示されない様子.

  • ipywidgetsのインストール
  • nodejsのインストール
  • JupyterLab Extensionのインストール

それぞれ順番にAnacondaプロンプトで実行する

conda install -c conda-forge ipywidgets
conda install -c conda-forge nodejs
jupyter labextension install @jupyter-widgets/jupyterlab-manager

しかし,上2つはうまくいったもののJupyter Extensionのインストールが出来ずつまづく.
どうやらJupyterLabのバージョンによってインストールのバージョンを指定する必要があるらしい.
私の使っているJupyterLabは2.2.6だったので

jupyter labextension install @jupyter-widgets/jupyterlab-manager@2

と実行してやっとインストールできた!
labの各バージョンにどのバージョンが対応しているのかどこを調べればいいのかわからず…
先駆者の方の記事を参考にさせて頂きました.
jupyter lab で tqdmつかうと改行されてわーとなるときは拡張機能オン

改めて実行

tqdm.py
import pandas as pd
import numpy as np
from tqdm.notebook import tqdm
import time

for i in tqdm(range(10)):
  time.sleep(1)

うまいこと動いた!!!!!!!
キャプチャ.PNG

おわりに

ということでtqdmを使ってプログレスバーの表示ができました.
何に使うか全然決まってないけどとりあえずできてよかったです.

参考記事

Pythonで進捗表示したい!
jupyter lab で tqdmつかうと改行されてわーとなるときは拡張機能オン
JupyterLabでtqdmを使えるようにするためにcondaでnodejsとipywidgetsをインストールする

8
9
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
8
9