Skip to content

Conversation

rnihesh
Copy link

@rnihesh rnihesh commented Apr 4, 2025

Fix: Update display import for compatibility with latest IPython


Description

This PR updates the import statement in displacy.render() to fix an ImportError caused by breaking changes in IPython 9+.

Replaced:

from IPython.core.display import HTML, display

With:

from IPython.display import HTML, display

The display function is no longer available in IPython.core.display in IPython 9 and above. This change ensures displacy.render() works correctly in Jupyter and notebook environments using newer versions of IPython.

Tested in:

  • Python 3.12.9 (venv)
  • IPython 9.0.2
  • JupyterLab
  • Confirmed displacy.render() now works without error.

Types of change

  • Bug fix

Checklist

  • I confirm that I have the right to submit this contribution under the project's MIT license.
  • I ran the tests, and all new and existing tests passed.
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

Fixes: #13763

@rnihesh rnihesh changed the title Fix: Update display import for compatibility with latest IPython Fix: Update display import for compatibility with latest IPython Fix: 13763 Apr 4, 2025
@rnihesh rnihesh changed the title Fix: Update display import for compatibility with latest IPython Fix: 13763 Fix: Update display import for compatibility with latest IPython Fixes: #13763 Apr 4, 2025
@majorgilles
Copy link

also ran into this issue, was about to submit my own PR

@ines
Copy link
Member

ines commented May 12, 2025

Thanks a lot and sorry for only getting to this now!

Just wondering if we should include a try/except here for backwards compatibility, even though it's not very pretty. Because I wouldn't want users on older IPython versions to run into problems going forward. This is probably the one thing I would add and then we can ship this (happy to do it before we release or you can also make an update) 🙂

@ines ines added bug Bugs and behaviour differing from documentation third-party Third-party packages and services feat / visualizers Feature: Built-in displaCy and other visualizers labels May 12, 2025
@rnihesh
Copy link
Author

rnihesh commented May 12, 2025

Yup working on that

@rnihesh
Copy link
Author

rnihesh commented May 12, 2025

done fixed

@celestinoxp
Copy link

@ines ping...

@wildfluss
Copy link

this is very annoying especially when working with prodigy :/ had to patch version which prodigy pulls etc

@it176131
Copy link
Contributor

it176131 commented Sep 2, 2025

Temporary solution until this is merged:

$ pip install -U "ipython<9"

@ondraz
Copy link

ondraz commented Oct 13, 2025

@honnibal or someone from spacy team please merge this. Thank you.

@rnihesh
Copy link
Author

rnihesh commented Oct 13, 2025

please merge this @ines @honnibal

try:
from IPython.display import HTML, display
except ImportError:
from IPython.core.display import HTML, display
Copy link

@Carreau Carreau Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPython maintainer here, the correct import has been from IPython.display import ... since 2012 (circa IPython 0.13), (or at least it should have been)

And in general you should avoid ImportError (it's unclear why, and use version numbers checking otherwise)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess your docs have been changed, when I raised this PR, I even saw the docs, specifying .core.display is to be used, can't get the link, but will add a reference here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THe docs are autogenerated, and it's not because an object is defined in IPython.core.display that it should be imported from there.

See how IPython/disaply.py defines

from IPython.core.display import * 

https://github.com/ipython/ipython/blob/rel-1.0.0/IPython/display.py#L15

Which (should) makes the .core unnecessary everywhere.

@Carreau
Copy link

Carreau commented Oct 14, 2025

Also if you have issues with IPython like that, feel free to ping me, I can always re-add the old imports for a few version if it breaks the world.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bugs and behaviour differing from documentation feat / visualizers Feature: Built-in displaCy and other visualizers third-party Third-party packages and services

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"from IPython.core.display import HTML, display" no more supported for latest IPython

8 participants