spaCy icon indicating copy to clipboard operation
spaCy copied to clipboard

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

Open tohuuuuu opened this issue 3 months ago • 4 comments

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:

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:

---------------------------------------------------------------------------
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('<span class="tex2jax_ignore">{}</span>'.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

tohuuuuu avatar Sep 07 '25 12:09 tohuuuuu

I can confirm. Same spacy version, same error.

DavidNemeskey avatar Oct 14 '25 13:10 DavidNemeskey

The same happened to me. Thanks for your workaround!

carloscardoso05 avatar Oct 15 '25 15:10 carloscardoso05

pip install ipython==7.23.1 This downgrade also worked for me @tohuuuuu - thanks a lot!

chrispydizzle avatar Nov 09 '25 19:11 chrispydizzle

Hi this issue is fixed by PR #13865

weezymatt avatar Dec 02 '25 09:12 weezymatt