Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spyder SymPy Wont Print Symbolic Math

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!

like image 561
Matt M. Avatar asked Jun 02 '14 18:06

Matt M.


People also ask

What does SymPy Init_printing () do?

With the help of sympy. init_printing() method, we are able to print the unicode characters for mathematical expressions.

Can you do symbolic math in Python?

SymPy is a Python library for symbolic mathematics. It aims to be an alternative to systems such as Mathematica or Maple while keeping the code as simple as possible and easily extensible. SymPy is written entirely in Python and does not require any external libraries.

How do you represent E in SymPy?

Note that by default in SymPy the base of the natural logarithm is E (capital E ). That is, exp(x) is the same as E**x .


1 Answers

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))
like image 111
asmeurer Avatar answered Oct 16 '22 17:10

asmeurer