Skip to content

Commit 5f55165

Browse files
committed
1.0.2rc1 catch IPython not installed
1 parent 8c0103e commit 5f55165

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

ReadMe.md

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ github](https://github.com/gutow/Algebra_with_Sympy/issues).
159159
vanilla python or Google Colab.
160160
* Workaround for Google Colab's inconsistent handling of mixed Latex and
161161
plain text strings. This impacted display of equation labels in Colab.
162+
* BUG FIX: catch IPython not installed so that can run in plain vanilla
163+
python.
162164
* 1.0.1 (May 22, 2024)
163165
* BUG FIX: equation labels that include underscore characters "_" are now
164166
accepted.

algebra_with_sympy/algebraic_equation.py

+22-7
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,10 @@ def integers_as_exact(self):
389389
return self.integers_as_exact
390390

391391
def __latex_override__(expr, *arg):
392-
from IPython import get_ipython
392+
try:
393+
from IPython import get_ipython
394+
except ModuleNotFoundError:
395+
pass
393396
colab = False
394397
try:
395398
from google.colab import output
@@ -449,8 +452,12 @@ def __command_line_printing__(expr, *arg):
449452
return print(tempstr + str(expr) + labelstr)
450453

451454
# Now we inject the formatting override(s)
452-
from IPython import get_ipython
453-
ip = get_ipython()
455+
ip = None
456+
try:
457+
from IPython import get_ipython
458+
ip = get_ipython()
459+
except ModuleNotFoundError:
460+
ip = false
454461
formatter = None
455462
if ip:
456463
# In an environment that can display typeset latex
@@ -485,7 +492,10 @@ def set_integers_as_exact():
485492
mode of algebra_with_sympy. To turn this off call
486493
`unset_integers_as_exact()`.
487494
"""
488-
from IPython import get_ipython
495+
try:
496+
from IPython import get_ipython
497+
except ModuleNotFoundError:
498+
pass
489499
if get_ipython():
490500
get_ipython().input_transformers_post.append(integers_as_exact)
491501
algwsym_config = get_ipython().user_ns.get("algwsym_config", False)
@@ -506,7 +516,10 @@ def unset_integers_as_exact():
506516
starts with `set_integers_as_exact()` enabled (
507517
`algwsym_config.numerics.integers_as_exact = True`).
508518
"""
509-
from IPython import get_ipython
519+
try:
520+
from IPython import get_ipython
521+
except ModuleNotFoundError:
522+
pass
510523
if get_ipython():
511524
pre = get_ipython().input_transformers_post
512525
# The below looks excessively complicated, but more reliably finds the
@@ -544,7 +557,10 @@ def units(names):
544557
"""
545558
from sympy.core.symbol import symbols
546559
#import __main__ as shell
547-
from IPython import get_ipython
560+
try:
561+
from IPython import get_ipython
562+
except ModuleNotFoundError:
563+
pass
548564
syms = names.split(' ')
549565
user_namespace = None
550566
retstr = ''
@@ -620,7 +636,6 @@ def solve(f, *symbols, **flags):
620636
"""
621637
from sympy.solvers.solvers import solve
622638
from sympy.sets.sets import FiniteSet
623-
from IPython.display import display
624639
newf =[]
625640
solns = []
626641
displaysolns = []

algebra_with_sympy/preparser.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,28 @@ def integers_as_exact(lines):
6666
off using the Algebra_with_sympy functions:
6767
* `set_integers_as_exact()`
6868
* `unset_integers_as_exact()`
69+
NOTE: This option does not work in plain vanilla Python sessions. You
70+
must be running in an IPython environment (Jupyter, Notebook, Colab,
71+
etc...).
6972
"""
7073
from sympy.interactive.session import int_to_Integer
7174
string = ''
7275
for k in lines:
7376
string += k + '\n'
7477
string = string[:-1] # remove the last '\n'
7578
return int_to_Integer(string)
76-
77-
from IPython import get_ipython
78-
if get_ipython():
79-
if hasattr(get_ipython(),'input_transformers_cleanup'):
80-
get_ipython().input_transformers_post.\
81-
append(algebra_with_sympy_preparser)
82-
else:
83-
import warnings
84-
warnings.warn('Compact equation input unavailable.\nYou will have ' \
85-
'to use the form "eq1 = Eqn(lhs,rhs)" instead of ' \
86-
'"eq1=@lhs=rhs".\nIt appears you are running an ' \
87-
'outdated version of IPython.\nTo fix, update IPython ' \
88-
'using "pip install -U IPython".')
79+
try:
80+
from IPython import get_ipython
81+
if get_ipython():
82+
if hasattr(get_ipython(),'input_transformers_cleanup'):
83+
get_ipython().input_transformers_post.\
84+
append(algebra_with_sympy_preparser)
85+
else:
86+
import warnings
87+
warnings.warn('Compact equation input unavailable.\nYou will have ' \
88+
'to use the form "eq1 = Eqn(lhs,rhs)" instead of ' \
89+
'"eq1=@lhs=rhs".\nIt appears you are running an ' \
90+
'outdated version of IPython.\nTo fix, update IPython ' \
91+
'using "pip install -U IPython".')
92+
except ModuleNotFoundError:
93+
pass

version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.0.2rc0'
1+
__version__ = '1.0.2rc1'

0 commit comments

Comments
 (0)