cannot import name 'display' from 'ipython.core.display'"
Fixes ImportError on `from ipython.core.display import display` after an IPython upgrade. Change the import to `from IPython.display import display` and grep the codebase for the old path. Not for missing ipykernel or kernel-process crashes.
TL;DR
IPython 9 removed the old ipython.core.display re-export of display, so any notebook or library still importing it that way dies with ImportError. Change the import line to from IPython.display import display (same for HTML, Image, Markdown). Then grep the repo for other ipython.core.display imports so the next cell does not hit the same wall.
ImportError: cannot import name 'display' from 'ipython.core.display'Use this when
- A notebook cell fails with ImportError naming
ipython.core.displayright after an IPython upgrade. - The traceback points at a library file that does
from ipython.core.display import displayorHTML. - You recently upgraded IPython past 8.x and old notebooks broke.
Not for this skill when
- The error is ModuleNotFoundError for
ipykernel. That is a missing kernel package, a different fix. - The kernel itself dies or segfaults. That is a binary/ABI problem, not an import path.
Steps
- Confirm the IPython version with
python -c "import IPython; print(IPython.__version__)". Verify: you see 9.x, where the old path is gone. - Find every old-style import:
grep -rn "ipython.core.display" --include=*.py --include=*.ipynb .. Verify: you have the full list of files to change. - Replace
from ipython.core.display import displaywithfrom IPython.display import displayin each file. Verify: a freshpython -c "from IPython.display import display"imports cleanly. - Restart the kernel and re-run the failing cell top to bottom. Verify: no ImportError and outputs render.
- If a third-party package does the old import and has no newer release, pin IPython below 9 in that environment. Verify: the package imports again in a fresh kernel.
Variant phrasings
importerror cannot import name display from ipython core display
The same failure with the ImportError prefix. Identical fix.
cannot import display from IPython after upgrade
The post-upgrade search phrasing. Same root cause, same one-line import change.
ipython.core.display deprecated
The historical framing. In current IPython the path is removed, not just deprecated.
Compatibility: IPython 8.x and 9.x. The from IPython.display import ... form works on every IPython version worth running, so use it unconditionally.
Why it happens
IPython moved its display helpers to the top-level IPython.display package years ago and kept ipython.core.display as a compatibility re-export. IPython 9 dropped that shim.
Edge cases / pitfalls
- Notebooks saved with the old import in many cells all need editing, not just the first one that errors.
- Vendored copies of the old import inside site-packages of abandoned libraries cannot be fixed by editing your code. Pin IPython or patch the library.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_C124ERHrlyxw5KV2tLN0sw