init_printing from sympy is no longer working in SageCell

73 views
Skip to first unread message

Sean Fitzpatrick

unread,
Feb 2, 2022, 12:42:48 PM2/2/22
to sage-support
I'm teaching a linear algebra course where we use the Sympy Python package for a lot of the computations. This includes a PreTeXt textbook where there are Sage Cells throughout, with sample code supplied.

Until today (I think it was working yesterday), I've had no trouble running code like the following:

from sympy import Matrix, init_printing
init_printing()
A = Matrix([[1,2,3,4],[5,6,7,8],[9,0,1,2]])
display(A.rref())

The init_printing function from Sympy renders the output in MathJax rather than pretty-printed plain text, which is nice for teaching. I can run this with the language set to either Sage or Python. (the 'display' command is only needed for Python, which is funny, because it is not needed in Jupyter with a Python kernel.)

Right now this code throws about 50 lines of error messages; the main error is a Type Error:

TypeError: Object of type <class 'bytes'> with value of '(a very, very long string that I won't reproduce here)' is not JSON serializable

Was there a change made today that would cause this error? Maybe in the Sympy library? If I remove the init_printing() line, everything works, except that there's no longer nice display for the output.

The reason for using Python syntax is that we also do labs in Jupyter notebooks. Our institution has a Jupyter hub with Python and R kernels, but no Sage kernel. (We do not have a CoCalc subscription.)

I know there is a Sage equivalent to init_printing (although I forget what it is) but that won't work on the Jupyter side.

Emmanuel Charpentier

unread,
Feb 2, 2022, 1:16:29 PM2/2/22
to sage-support
WorksForMe(TM) in Sage 9.5, in both Jupyter and Jupyterlab...

HTH,

Henri Girard

unread,
Feb 2, 2022, 1:39:40 PM2/2/22
to sage-s...@googlegroups.com

 I tried it in sage 9.2 nice printing.

But in sage I use show(LatexExpr("r \mu \epsilon))

μϵ

I am not sure that what you want (and naturaly first command in cell %display latex        in sage)

One can even format text in a beautifull latex

show(LatexExpr(r"This \ is \ \mu \ and \ \epsilon"))

This is μ and ϵ

best

 Best

Henri
--
You received this message because you are subscribed to the Google Groups "sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-support...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/0262ca41-4a74-467b-8f46-0af9ad6c4df1n%40googlegroups.com.

Sean Fitzpatrick

unread,
Feb 2, 2022, 2:09:52 PM2/2/22
to sage-support
This is in SageMathCell, rather than in a local installation of Sage. I don't think there's much I can do about what is running on here.
sagecell.png

Sean Fitzpatrick

unread,
Feb 2, 2022, 2:28:11 PM2/2/22
to sage-support
Here is an example with Sage cells in context:

If I remove the init_printing() line, or change this to init_printing(use_latex=False), the code will run, but I lose the MathJax-formatted output.

I can't tell if this is a bug in the init_printing() function (to my knowledge, there is no recent update to Sympy -- I upgraded my local Python installation and everything is still working) or if something is going wrong with Sage Cell trying to process the output.

Andrey Novoseltsev

unread,
Feb 2, 2022, 4:34:17 PM2/2/22
to sage-support
This is due to recent upgrade to Sage 9.5. I will try to have it fixed in a few hours or revert to 9.4 until I figure out the fix.

Sean Fitzpatrick

unread,
Feb 2, 2022, 4:35:35 PM2/2/22
to sage-support
Thanks! I just discovered that there is a separate group for Sage Cell.
Oddly, the SageCell page links here for help! Apologies for not posting there first.

Andrey Novoseltsev

unread,
Feb 2, 2022, 4:48:36 PM2/2/22
to sage-support
On Wednesday, 2 February 2022 at 14:35:35 UTC-7 dsfitz...@gmail.com wrote:
Thanks! I just discovered that there is a separate group for Sage Cell.
Oddly, the SageCell page links here for help! Apologies for not posting there first.

This is on purpose - most questions people have are about Sage itself and they will get much better and faster help here ;-) 
Reply all
Reply to author
Forward
0 new messages