sympy icon indicating copy to clipboard operation
sympy copied to clipboard

sympy.physics.mechanics - AttributeError: 'Fake' object has no attribute 'height' when showing a vector and a dyadic

Open Davide-sd opened this issue 6 months ago • 2 comments

On Jupyter Notebook, when I attempt to show a vector and a dyadic on the same cell, I get the following error:

from sympy import *
from sympy.physics.mechanics import *
init_vprinting()

N = ReferenceFrame("N")
v = 0 * N.x
i = N.x.outer(N.x)
v, i
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File [~/Documents/Development/envs/plot/lib/python3.12/site-packages/IPython/core/formatters.py:711](http://localhost:8888/lab/tree/Dynamics/envs/plot/lib/python3.12/site-packages/IPython/core/formatters.py#line=710), in PlainTextFormatter.__call__(self, obj)
    704 stream = StringIO()
    705 printer = pretty.RepresentationPrinter(stream, self.verbose,
    706     self.max_width, self.newline,
    707     max_seq_length=self.max_seq_length,
    708     singleton_pprinters=self.singleton_printers,
    709     type_pprinters=self.type_printers,
    710     deferred_pprinters=self.deferred_printers)
--> 711 printer.pretty(obj)
    712 printer.flush()
    713 return stream.getvalue()

File [~/Documents/Development/envs/plot/lib/python3.12/site-packages/IPython/lib/pretty.py:394](http://localhost:8888/lab/tree/Dynamics/envs/plot/lib/python3.12/site-packages/IPython/lib/pretty.py#line=393), in RepresentationPrinter.pretty(self, obj)
    391 for cls in _get_mro(obj_class):
    392     if cls in self.type_pprinters:
    393         # printer registered in self.type_pprinters
--> 394         return self.type_pprinters[cls](obj, self, cycle)
    395     else:
    396         # deferred printer
    397         printer = self._in_deferred_types(cls)

File [~/Documents/Development/envs/plot/lib/python3.12/site-packages/sympy/interactive/printing.py:82](http://localhost:8888/lab/tree/Dynamics/envs/plot/lib/python3.12/site-packages/sympy/interactive/printing.py#line=81), in _init_ipython_printing.<locals>._print_plain(arg, p, cycle)
     80 """caller for pretty, for use in IPython 0.11"""
     81 if _can_print(arg):
---> 82     p.text(stringify_func(arg))
     83 else:
     84     p.text(IPython.lib.pretty.pretty(arg))

File [~/Documents/Development/envs/plot/lib/python3.12/site-packages/sympy/physics/vector/printing.py:285](http://localhost:8888/lab/tree/Dynamics/envs/plot/lib/python3.12/site-packages/sympy/physics/vector/printing.py#line=284), in vpprint(expr, **settings)
    282 uflag = pretty_use_unicode(use_unicode)
    284 try:
--> 285     return pp.doprint(expr)
    286 finally:
    287     pretty_use_unicode(uflag)

File [~/Documents/Development/envs/plot/lib/python3.12/site-packages/sympy/printing/pretty/pretty.py:66](http://localhost:8888/lab/tree/Dynamics/envs/plot/lib/python3.12/site-packages/sympy/printing/pretty/pretty.py#line=65), in PrettyPrinter.doprint(self, expr)
     65 def doprint(self, expr):
---> 66     return self._print(expr).render(**self._settings)

File [~/Documents/Development/envs/plot/lib/python3.12/site-packages/sympy/printing/printer.py:331](http://localhost:8888/lab/tree/Dynamics/envs/plot/lib/python3.12/site-packages/sympy/printing/printer.py#line=330), in Printer._print(self, expr, **kwargs)
    329     printmethod = getattr(self, printmethodname, None)
    330     if printmethod is not None:
--> 331         return printmethod(expr, **kwargs)
    332 # Unknown object, fall back to the emptyPrinter.
    333 return self.emptyPrinter(expr)

File [~/Documents/Development/envs/plot/lib/python3.12/site-packages/sympy/printing/pretty/pretty.py:2397](http://localhost:8888/lab/tree/Dynamics/envs/plot/lib/python3.12/site-packages/sympy/printing/pretty/pretty.py#line=2396), in PrettyPrinter._print_tuple(self, t)
   2395     return prettyForm(*ptuple.parens('(', ')', ifascii_nougly=True))
   2396 else:
-> 2397     return self._print_seq(t, '(', ')')

File [~/Documents/Development/envs/plot/lib/python3.12/site-packages/sympy/printing/pretty/pretty.py:2369](http://localhost:8888/lab/tree/Dynamics/envs/plot/lib/python3.12/site-packages/sympy/printing/pretty/pretty.py#line=2368), in PrettyPrinter._print_seq(self, seq, left, right, delimiter, parenthesize, ifascii_nougly)
   2367     s = stringPict('')
   2368 else:
-> 2369     s = prettyForm(*stringPict.next(*pforms))
   2371 s = prettyForm(*s.parens(left, right, ifascii_nougly=ifascii_nougly))
   2372 return s

File [~/Documents/Development/envs/plot/lib/python3.12/site-packages/sympy/printing/pretty/stringpict.py:71](http://localhost:8888/lab/tree/Dynamics/envs/plot/lib/python3.12/site-packages/sympy/printing/pretty/stringpict.py#line=70), in stringPict.next(*args)
     69 #make a list of pictures, with equal height and baseline
     70 newBaseline = max(obj.baseline for obj in objects)
---> 71 newHeightBelowBaseline = max(
     72     obj.height() - obj.baseline
     73     for obj in objects)
     74 newHeight = newBaseline + newHeightBelowBaseline
     76 pictures = []

File [~/Documents/Development/envs/plot/lib/python3.12/site-packages/sympy/printing/pretty/stringpict.py:72](http://localhost:8888/lab/tree/Dynamics/envs/plot/lib/python3.12/site-packages/sympy/printing/pretty/stringpict.py#line=71), in <genexpr>(.0)
     69 #make a list of pictures, with equal height and baseline
     70 newBaseline = max(obj.baseline for obj in objects)
     71 newHeightBelowBaseline = max(
---> 72     obj.height() - obj.baseline
     73     for obj in objects)
     74 newHeight = newBaseline + newHeightBelowBaseline
     76 pictures = []

AttributeError: 'Fake' object has no attribute 'height'

At the end of the error message, the output shows up correctly:

image

Davide-sd avatar Aug 14 '24 08:08 Davide-sd