문제

I setup Anaconda 2.0.0 (Win 64). It has SymPy 0.7.5.

I configured Spyder (2.3.0rc that came with Anaconda) to use symbolic math:

Tools > Preferences > iPython console > Advanced Settings > Symbolic Mathematics

I create a new project and a new file:

# -*- coding: utf-8 -*-
from sympy import *
init_printing(use_unicode=False, wrap_line=False, no_global=True)

x = Symbol('x')
integrate(x, x)

print("Completed.")

When I run this (Python or iPython console) it does not print the integral -- it only prints Completed.

But what is weird is that while in the console that just did the run if I then re-type:

integrate(x, x)

It does print the integral.

So running from a file never prints any symbolic math but typing in the console manually does?

Can anyone help with this issue -- maybe it some sort of configuration?

Thank you!

도움이 되었습니까?

해결책

Running a script is not the same as executing code in IPython. When you run the code in a cell or prompt in IPython, it captures the output of the last command and displays it to you. When you run a script, the script is just run, and the only thing that is displayed is what is printed to the screen.

I don't think there is a way to send the IPython display object (which would be needed to get pretty latex output) from a script, but I may be misunderstanding how spyder executes the code in IPython, or missing some hooks that it has. You can try

from IPython.display import display
display(integrate(x, x))

다른 팁

It is because integrate doesn't print automatically, it just returns the output. You will have to pass it to print function to get the output. Try using following code:

# -*- coding: utf-8 -*-
from sympy import *
init_printing(use_unicode=False, wrap_line=False, no_global=True)
x = Symbol('x')
print(integrate(x, x))
print("Completed.")

In Python console(or IPython console) returned statements are automatically printed.

Update: Use pprint for a nice formatted output.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top