diff --git a/CHANGELOG.md b/CHANGELOG.md index 64c0441fd65dc..11ae87fa79c6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ## [unreleased] - YYYY-MM-DD +### Fixed + +- Fixed crashing or wrong displaying progressbar because of missing ipywidgets ([#2417](https://github.com/PyTorchLightning/pytorch-lightning/pull/2417)) + ### Added @@ -20,7 +24,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Fixed - ## [0.8.3] - 2020-06-29 ### Fixed diff --git a/pytorch_lightning/callbacks/progress.py b/pytorch_lightning/callbacks/progress.py index 358575273f945..472d245f4f1b2 100644 --- a/pytorch_lightning/callbacks/progress.py +++ b/pytorch_lightning/callbacks/progress.py @@ -5,9 +5,16 @@ Use or override one of the progress bar callbacks. """ +import importlib import sys -from tqdm.auto import tqdm + +# check if ipywidgets is installed before importing tqdm.auto +# to ensure it won't fail and a progress bar is displayed +if importlib.util.find_spec('ipywidgets') is not None: + from tqdm.auto import tqdm +else: + from tqdm import tqdm from pytorch_lightning.callbacks import Callback diff --git a/pytorch_lightning/trainer/lr_finder.py b/pytorch_lightning/trainer/lr_finder.py index 72228c81394ba..19ba13f588ce3 100755 --- a/pytorch_lightning/trainer/lr_finder.py +++ b/pytorch_lightning/trainer/lr_finder.py @@ -1,6 +1,8 @@ """ Trainer Learning Rate Finder """ +import os +import importlib from abc import ABC, abstractmethod from typing import Optional, Sequence, Tuple, List, Union @@ -8,8 +10,14 @@ import torch from torch.optim.lr_scheduler import _LRScheduler from torch.utils.data import DataLoader -from tqdm.auto import tqdm -import os + +# check if ipywidgets is installed before importing tqdm.auto +# to ensure it won't fail and a progress bar is displayed +if importlib.util.find_spec('ipywidgets') is not None: + from tqdm.auto import tqdm +else: + from tqdm import tqdm + from pytorch_lightning.core.lightning import LightningModule from pytorch_lightning.callbacks import Callback