spaCy icon indicating copy to clipboard operation
spaCy copied to clipboard

vscode doesn't like displacy.render(sentence1, style="dep")

Open kundeng opened this issue 8 months ago • 5 comments

How to reproduce the behaviour


ImportError                               Traceback (most recent call last)
Cell In[44], line 2
      1 from spacy import displacy
----> 2 displacy.render(sentence1, style="dep")

File c:\Users\kundeng\scoop\persist\mambaforge\envs\spacy\Lib\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' (c:\Users\xxx\scoop\persist\mambaforge\envs\spacy\Lib\site-packages\IPython\core\display.py)

Your Environment

  • Operating System: Windows 11
  • Python Version Used: python 3.12.10
  • spaCy Version Used: 3.8.5
  • Environment Information: Conda Mamaforge

kundeng avatar Apr 27 '25 21:04 kundeng

Well actually I'm pretty sure it's because spacy relies on iPython 8.x, but what I have is 9.x.

kundeng avatar Apr 27 '25 21:04 kundeng

@kundeng explicitly installing 8.x of iPython in my environment fixed it for me.

jeppe-style avatar Apr 28 '25 12:04 jeppe-style

Thanks. Downgrading iPython to v8.x from v9 fixed the issue on Linux + Python 3.11.

lukeic avatar May 10 '25 00:05 lukeic

The issue is in the import from IPython.core.display. In the new version it should be IPython.display. That does work for me

MasterDisaster7 avatar Jul 16 '25 11:07 MasterDisaster7

The issue is in the import from IPython.core.display. In the new version it should be IPython.display. That does work for me

import sys from IPython import display sys.modules['IPython.core.display'] = display

this fixed it for me, thanks!

therake210 avatar Oct 01 '25 13:10 therake210