Skip to content

Commit 1a54ed6

Browse files
Checking ipywidgets is installed for ensure tqdm working (#2417)
* Adding importing ipywidgets before importing tqdm.auto to make sure ipywidgets is installed. * Updated CHANGELOG.md * Updated ipywidgets importing checks to @awaelchli comments. Co-authored-by: William Falcon <[email protected]>
1 parent 309ed75 commit 1a54ed6

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
66

77
## [unreleased] - YYYY-MM-DD
88

9+
### Fixed
10+
11+
- Fixed crashing or wrong displaying progressbar because of missing ipywidgets ([#2417](https://github.com/PyTorchLightning/pytorch-lightning/pull/2417))
12+
913
### Added
1014

1115

@@ -20,7 +24,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
2024

2125
### Fixed
2226

23-
2427
## [0.8.3] - 2020-06-29
2528

2629
### Fixed

pytorch_lightning/callbacks/progress.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55
Use or override one of the progress bar callbacks.
66
77
"""
8+
import importlib
89
import sys
910

10-
from tqdm.auto import tqdm
11+
12+
# check if ipywidgets is installed before importing tqdm.auto
13+
# to ensure it won't fail and a progress bar is displayed
14+
if importlib.util.find_spec('ipywidgets') is not None:
15+
from tqdm.auto import tqdm
16+
else:
17+
from tqdm import tqdm
1118

1219
from pytorch_lightning.callbacks import Callback
1320

pytorch_lightning/trainer/lr_finder.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
"""
22
Trainer Learning Rate Finder
33
"""
4+
import os
5+
import importlib
46
from abc import ABC, abstractmethod
57
from typing import Optional, Sequence, Tuple, List, Union
68

79
import numpy as np
810
import torch
911
from torch.optim.lr_scheduler import _LRScheduler
1012
from torch.utils.data import DataLoader
11-
from tqdm.auto import tqdm
12-
import os
13+
14+
# check if ipywidgets is installed before importing tqdm.auto
15+
# to ensure it won't fail and a progress bar is displayed
16+
if importlib.util.find_spec('ipywidgets') is not None:
17+
from tqdm.auto import tqdm
18+
else:
19+
from tqdm import tqdm
20+
1321

1422
from pytorch_lightning.core.lightning import LightningModule
1523
from pytorch_lightning.callbacks import Callback

0 commit comments

Comments
 (0)