@@ -389,8 +389,12 @@ def integers_as_exact(self):
389
389
return self .integers_as_exact
390
390
391
391
def __latex_override__ (expr , * arg ):
392
+ algwsym_config = False
393
+ ip = False
392
394
try :
393
395
from IPython import get_ipython
396
+ if get_ipython ():
397
+ ip = True
394
398
except ModuleNotFoundError :
395
399
pass
396
400
colab = False
@@ -401,7 +405,7 @@ def __latex_override__(expr, *arg):
401
405
pass
402
406
show_code = False
403
407
latex_as_equations = False
404
- if get_ipython () :
408
+ if ip :
405
409
algwsym_config = get_ipython ().user_ns .get ("algwsym_config" , False )
406
410
else :
407
411
algwsym_config = globals ()['algwsym_config' ]
@@ -492,17 +496,20 @@ def set_integers_as_exact():
492
496
mode of algebra_with_sympy. To turn this off call
493
497
`unset_integers_as_exact()`.
494
498
"""
499
+ ip = False
495
500
try :
496
501
from IPython import get_ipython
502
+ ip = True
497
503
except ModuleNotFoundError :
498
- pass
499
- if get_ipython ():
500
- get_ipython ().input_transformers_post .append (integers_as_exact )
501
- algwsym_config = get_ipython ().user_ns .get ("algwsym_config" , False )
502
- if algwsym_config :
503
- algwsym_config .numerics .integers_as_exact = True
504
- else :
505
- raise ValueError ("The algwsym_config object does not exist." )
504
+ ip = False
505
+ if ip :
506
+ if get_ipython ():
507
+ get_ipython ().input_transformers_post .append (integers_as_exact )
508
+ algwsym_config = get_ipython ().user_ns .get ("algwsym_config" , False )
509
+ if algwsym_config :
510
+ algwsym_config .numerics .integers_as_exact = True
511
+ else :
512
+ raise ValueError ("The algwsym_config object does not exist." )
506
513
return
507
514
508
515
def unset_integers_as_exact ():
@@ -516,22 +523,25 @@ def unset_integers_as_exact():
516
523
starts with `set_integers_as_exact()` enabled (
517
524
`algwsym_config.numerics.integers_as_exact = True`).
518
525
"""
526
+ ip = False
519
527
try :
520
528
from IPython import get_ipython
529
+ ip = True
521
530
except ModuleNotFoundError :
522
- pass
523
- if get_ipython ():
524
- pre = get_ipython ().input_transformers_post
525
- # The below looks excessively complicated, but more reliably finds the
526
- # transformer to remove across varying IPython environments.
527
- for k in pre :
528
- if "integers_as_exact" in k .__name__ :
529
- pre .remove (k )
530
- algwsym_config = get_ipython ().user_ns .get ("algwsym_config" , False )
531
- if algwsym_config :
532
- algwsym_config .numerics .integers_as_exact = False
533
- else :
534
- raise ValueError ("The algwsym_config object does not exist." )
531
+ ip = False
532
+ if ip :
533
+ if get_ipython ():
534
+ pre = get_ipython ().input_transformers_post
535
+ # The below looks excessively complicated, but more reliably finds the
536
+ # transformer to remove across varying IPython environments.
537
+ for k in pre :
538
+ if "integers_as_exact" in k .__name__ :
539
+ pre .remove (k )
540
+ algwsym_config = get_ipython ().user_ns .get ("algwsym_config" , False )
541
+ if algwsym_config :
542
+ algwsym_config .numerics .integers_as_exact = False
543
+ else :
544
+ raise ValueError ("The algwsym_config object does not exist." )
535
545
536
546
return
537
547
@@ -557,16 +567,17 @@ def units(names):
557
567
"""
558
568
from sympy .core .symbol import symbols
559
569
#import __main__ as shell
570
+ user_namespace = None
560
571
try :
561
572
from IPython import get_ipython
573
+ if get_ipython ():
574
+ user_namespace = get_ipython ().user_ns
562
575
except ModuleNotFoundError :
563
576
pass
564
577
syms = names .split (' ' )
565
- user_namespace = None
566
578
retstr = ''
567
- if get_ipython ():
568
- user_namespace = get_ipython ().user_ns
569
- else :
579
+
580
+ if user_namespace == None :
570
581
import sys
571
582
frame_num = 0
572
583
frame_name = None
@@ -703,7 +714,6 @@ def solveset(f, symbols, domain=sympy.Complexes):
703
714
equations unless you directly select `linsolve`, etc...
704
715
"""
705
716
from sympy .solvers import solveset as solve
706
- from IPython .display import display
707
717
newf = []
708
718
solns = []
709
719
displaysolns = []
0 commit comments