Skip to content

Commit 82ffe4e

Browse files
committed
only define cell magics if IPython is loaded
1 parent 73841a4 commit 82ffe4e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/ogdf_python/jupyter.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
import cppyy
44

5-
try:
5+
ip = None
6+
if "IPython" in sys.modules:
67
from IPython import get_ipython
8+
9+
ip = get_ipython()
10+
11+
if ip is not None:
712
from IPython.core.magic import register_cell_magic
8-
if not get_ipython():
9-
raise ImportError("cell magic can only be used in context where `get_ipython` exists")
10-
except ImportError:
11-
pass
12-
else:
13+
1314
cppyy.cppdef("""
1415
#include <sstream>
1516
#include <streambuf>

0 commit comments

Comments
 (0)