Ipython 打印正确的数学格式

Ipython 打印正确的数学格式,ipython,sympy,Ipython,Sympy,当我使用sympy得到8的平方根时,输出结果很难看: 2*2**(1/2) 有没有办法使sympy以正确的数学符号打印输出(即使用正确的平方根符号) 更新: 当我遵循@pqnet的命令时: from sympy import * x, y, z = symbols('x y z') init_printing() init_session() 我发现以下错误: -------------------------------------------------------------------

当我使用
sympy
得到8的平方根时,输出结果很难看:

2*2**(1/2)

有没有办法使
sympy
以正确的数学符号打印输出(即使用正确的平方根符号)

更新: 当我遵循@pqnet的命令时:

from sympy import *
x, y, z = symbols('x y z')
init_printing()
init_session()
我发现以下错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-23-21d886bf3e54> in <module>()
      2 x, y, z = symbols('x y z')
      3 init_printing()
----> 4 init_session()

/usr/lib/python2.7/dist-packages/sympy/interactive/session.pyc in init_session(ipython, pretty_print, order, use_unicode, quiet, argv)
    154                 # and False means don't add the line to IPython's history.
    155                 ip.runsource = lambda src, symbol='exec': ip.run_cell(src, False)
--> 156                 mainloop = ip.mainloop
    157             else:
    158                 mainloop = ip.interact

AttributeError: 'ZMQInteractiveShell' object has no attribute 'mainloop'
---------------------------------------------------------------------------
AttributeError回溯(最近一次呼叫上次)
在()
2 x,y,z=符号('x y z')
3初始打印()
---->4初始会话()
/初始化会话中的usr/lib/python2.7/dist-packages/sympy/interactive/session.pyc(ipython、pretty\u print、order、use\u unicode、quiet、argv)
154#和False的意思是不要在IPython的历史中添加线。
155 ip.runsource=lambda src,symbol='exec':ip.run\u单元格(src,False)
-->156 mainloop=ip.mainloop
157.其他:
158 mainloop=ip.interact
AttributeError:'ZMQInteractiveShell'对象没有属性'mainloop'

最简单的方法是:

sympy.pprint(sympy.sqrt(8))
对我来说(使用rxvt-unicode和ipython),它提供了


在ipython笔记本电脑中,您可以使用
init_printing
功能启用Symphy的图形数学排版:

import sympy
sympy.init_printing(use_latex='mathjax')
之后,Symphy将截取每个单元格的输出,并使用数学字体和符号对其进行格式化。尝试:

sympy.sqrt(8)
另见:

  • 在公园里

你的意思是,像图形显示一样?@pqnet-我不知道你叫什么“图形显示”。我想到的是,打印平方根的数学符号,而不是
sqrt()
code。我想说的是,您是想要结果的一些图形化呈现,还是只希望它以unicode格式输出,如下所示:
2*√(2) 
@pqnet-哦,我明白了。我想对结果进行图形化渲染。如果我遇到很多错误,例如
不支持操作
,还有许多更有趣的问题,您使用的是什么终端仿真器?还有什么pythonshell呢?我正在使用
ipython笔记本
chrome的ipython笔记本对我来说效果很好。您可以尝试更新sympy、python、ipython或浏览器的版本吗?或者尝试在其他浏览器中运行,或者禁用所有加载项?除此之外,我想我帮不了什么忙。对不起。
import sympy
sympy.init_printing(use_latex='mathjax')
sympy.sqrt(8)