diff --git a/spacy/displacy/__init__.py b/spacy/displacy/__init__.py index 965bfbddf..660ae1984 100644 --- a/spacy/displacy/__init__.py +++ b/spacy/displacy/__init__.py @@ -9,10 +9,9 @@ from ..util import prints, is_in_jupyter _html = {} -IS_JUPYTER = is_in_jupyter() -def render(docs, style='dep', page=False, minify=False, jupyter=IS_JUPYTER, +def render(docs, style='dep', page=False, minify=False, jupyter=False, options={}, manual=False): """Render displaCy visualisation. @@ -39,7 +38,7 @@ def render(docs, style='dep', page=False, minify=False, jupyter=IS_JUPYTER, parsed = [converter(doc, options) for doc in docs] if not manual else docs _html['parsed'] = renderer.render(parsed, page=page, minify=minify).strip() html = _html['parsed'] - if jupyter: # return HTML rendered by IPython display() + if jupyter or is_in_jupyter(): # return HTML rendered by IPython display() from IPython.core.display import display, HTML return display(HTML(html)) return html diff --git a/spacy/util.py b/spacy/util.py index 290d5eba5..9ad2665ca 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -222,15 +222,15 @@ def get_package_path(name): def is_in_jupyter(): """Check if user is running spaCy from a Jupyter notebook by detecting the IPython kernel. Mainly used for the displaCy visualizer. - RETURNS (bool): True if in Jupyter, False if not. """ + # https://stackoverflow.com/a/39662359/6400719 try: - cfg = get_ipython().config - if cfg['IPKernelApp']['parent_appname'] == 'ipython-notebook': - return True + shell = get_ipython().__class__.__name__ + if shell == "ZMQInteractiveShell": + return True # Jupyter notebook or qtconsole except NameError: - return False + return False # Probably standard Python interpreter return False