Guillaume-Garrigos / latexify

A tool for converting numerous python objects (numpy, sympy) into latex strings
MIT License
8 stars 0 forks source link

AttributeError: module 'sympy' has no attribute 'numbers' #1

Open atbradley opened 3 years ago

atbradley commented 3 years ago

Calling latexify(Fraction(3,8)) throws this error:

AttributeError                            Traceback (most recent call last)
<ipython-input-31-72bf10122832> in <module>
----> 1 latexify(Fraction(3,8))

~/.local/lib/python3.7/site-packages/latexifier/latexifier.py in latexify(x, verbose, **param)
    386 def latexify(x, verbose=False, **param):
    387     param = get_parameters(**param)
--> 388     latex = latexifier(x, **param)
    389 
    390     if param['newline']:

~/.local/lib/python3.7/site-packages/latexifier/latexifier.py in latexifier(x, **param)
    376         latex = numpyarray_to_latex(x, column=True, **param)
    377     elif isinstance(x, numbers.Number):
--> 378         latex = number_to_latex(x, **param)
    379     elif isinstance(x, sympy.Basic):
    380         latex = sympy_to_latex(x, **param)

~/.local/lib/python3.7/site-packages/latexifier/latexifier.py in number_to_latex(x, **param)
    284 
    285 def number_to_latex(x, **param):
--> 286     return number_to_algebraic(x, **param)[0]
    287 
    288 def simplify_number(x, **param):

~/.local/lib/python3.7/site-packages/latexifier/latexifier.py in number_to_algebraic(x, **param)
    238             if isinstance(x, numbers.Real):
    239                 if isinstance(x, numbers.Rational):
--> 240                     if isinstance(x, numbers.Integral) or isinstance(x, sympy.numbers.Integer): # x is an integer TRICKY : https://stackoverflow.com/questions/48458438/why-is-numpy-int32-not-recognized-as-an-int-type
    241                         latex = str(x)
    242                     elif isinstance(x, Fraction): # x is a Fraction

AttributeError: module 'sympy' has no attribute 'numbers'

A call to Math(latexify(3/8)) avoids this line and this error.

Guillaume-Garrigos commented 3 years ago

Hi Adam,

For me the following code

from latexifier import latexify
from fractions import Fraction
latexify(Fraction(3,8))

returns '\\frac{3}{8}' as expected, so I cannot reproduce your error. I see two possible explanations:

  1. You are using another Fraction module. If so could you provide a minimal working example?
  2. Dependency/module version issues. This one would be more tricky to detect.
runan520 commented 1 week ago

try change sympy.numbers.Integer to sympy.core.Integer