explosion / explosion/spaCy

displaycy.render yields ImportError: cannot import name 'display' from 'IPython.core.display' when in Jupyter Mode

Open
#13,871 4 comments 15 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
33.9k
Forks
4.7k
Avg merge
3m
Merged PRs (30d)
1

Description

## Problem
`displaycy.render` seems to be broken when used in Jupyter Mode with a current ipython version. The method yields an `ImportError: cannot import name 'display' from 'IPython.core.display'` when in Jupyter Mode.

## How to reproduce the behaviour
Run the following example code inside a Jupyter Notebook:
```python
import spacy
from spacy import displacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("This is a sentence.")
displacy.render(doc, style="dep", jupyter=True)
```

This yields the following error:
```python
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[1], line 5
3 nlp = spacy.load("en_core_web_sm")
4 doc = nlp("This is a sentence.")
----> 5 displacy.render(doc, style="dep", jupyter=True)

File ~/abc/.venv/lib/python3.12/site-packages/spacy/displacy/__init__.py:69, in render(docs, style, page, minify, jupyter, options, manual)
65 html = RENDER_WRAPPER(html)
66 if jupyter or (jupyter is None and is_in_jupyter()):
67 # return HTML rendered by IPython display()
68 # See #4840 for details on span wrapper to disable mathjax
---> 69 from IPython.core.display import HTML, display
71 return display(HTML('{}'.format(html)))
72 return html

ImportError: cannot import name 'display' from 'IPython.core.display' (/home/xyz/abc/.venv/lib/python3.12/site-packages/IPython/core/display.py)
```

## Your Environment

- **spaCy version:** 3.8.7
- **Platform:** Linux-6.8.0-79-generic-x86_64-with-glibc2.39
- **Python version:** 3.12.3
- **Pipelines:** en_core_web_sm (3.8.0)

## My Workaround

Downgrade ipython to 7.23.1:
`pip install ipython==7.23.1`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.