Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using a sage function standalone within python

Tags:

python

sage

There is a function within sage, latex, that I want to use in directly from the command line, without dropping into sage the sage client. one way I think this may be possible is to include that sage module into my python script.

using pip install sage doesn't work.

any ideas?

like image 356
tipu Avatar asked May 13 '12 20:05

tipu


2 Answers

You can't just install Sage as a package with a package, and there is tons of non-Python code in Sage, so it would be hard to do this a priori.

However, you can call Sage from a script pretty easily. Here is an example.

For anyone finding this, in general ask.sagemath.org is going to be a quicker way to get responses - I didn't even know that stackoverflow had a Sage tag.

like image 78
kcrisman Avatar answered Sep 29 '22 20:09

kcrisman


Yes, but only if you run the script using the special version of Python that is bundled with Sage.

From Sage's docs http://www.sagemath.org/doc/faq/faq-usage.html#how-do-i-import-sage-into-a-python-script

You can import Sage as a library in a Python script. One caveat is that you need to run that Python script using the version of Python that is bundled with Sage; currently Python 2.6.x. To import Sage, put the following in your Python script:

from sage.all import *
like image 39
Colonel Panic Avatar answered Sep 29 '22 19:09

Colonel Panic