diff --git a/src/prompt_toolkit/application/application.py b/src/prompt_toolkit/application/application.py index 726fc0a06..c07ea4e94 100644 --- a/src/prompt_toolkit/application/application.py +++ b/src/prompt_toolkit/application/application.py @@ -960,7 +960,8 @@ def run_in_thread() -> None: def _called_from_ipython() -> bool: try: return ( - "IPython/terminal/interactiveshell.py" + sys.modules["IPython"].version_info < (8, 18, 0, "") + and "IPython/terminal/interactiveshell.py" in sys._getframe(3).f_code.co_filename ) except BaseException: