From 26008225a7d49e4eb3b8fff06f141e4f0b3eecc9 Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Fri, 9 Feb 2024 13:15:28 +0000 Subject: [PATCH] Automatically load ipython extension --- pysr/julia_import.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pysr/julia_import.py b/pysr/julia_import.py index aaaa262b0..575dddffb 100644 --- a/pysr/julia_import.py +++ b/pysr/julia_import.py @@ -29,6 +29,19 @@ ): os.environ[k] = os.environ.get(k, default) + +def is_in_jupyter() -> bool: + try: + ipy = get_ipython().__class__.__name__ # type: ignore + return ipy == "ZMQInteractiveShell" + except NameError: + return False + + +if is_in_jupyter(): + get_ipython().run_line_magic("load_ext", "julia.ipython") # type: ignore + + from juliacall import Main as jl # type: ignore