DCASE-REPO / dcase_util

A collection of utilities for Detection and Classification of Acoustic Scenes and Events
https://dcase-repo.github.io/dcase_util/
MIT License
127 stars 33 forks source link

dcase.util.utils.is_jupyter() cause ModuleNotFoundError #40

Closed E-train-Liu closed 2 years ago

E-train-Liu commented 2 years ago

Description

NoModuleFoundError raised when using dcase_util.utils.is_jupyter() and other functions calling it.

Steps/Code to Reproduce

import dcase_util.utils
print(dcase.util.utils.is_jupyter())

Expected Results

If there is no Jupyter or IPython installed, it should show

False

Actual Results

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "<path to conda environment>/lib/site-packages/dcase_util/utils/utils.py", line 191, in is_jupyter
    from IPython import get_ipython
ModuleNotFoundError: No module named 'IPython'

Versions

conda 4.9.0
Python 3.8.12 (default, Oct 12 2021, 03:01:40) [MSC v.1916 64 bit (AMD64)]
NumPy 1.19.2
SciPy 1.8.0
Matplotlib 3.5.1
librosa 0.9.1

Note: no IPython module installed in this environment.

Cause

It tried from IPython import get_ipython, if get_ipython dose not exist, it will catch a NameError and return False.

However, this actually assumes that there is IPython. If IPython or Jupyter is not installed, an ModuleNotFoundError will be raised and cannot be correctly caught.

Possible Fix

Change line https://github.com/DCASE-REPO/dcase_util/blob/master/dcase_util/utils/utils.py#L208 to be

    except (ModuleNotFoundError, NameError):
toni-heittola commented 2 years ago

Thanks for spotting the issue. This issue has been addressed now with commit ab4245885445f171b42e01f2da4640854ff7e710 (develop branch).