7

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?

tipu
  • 9,464
  • 15
  • 65
  • 98

2 Answers2

15

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.

kcrisman
  • 4,374
  • 20
  • 41
  • 4
    For any Sage devs reading this, you can subscribe to email updates for stackoverflow questions with a certain tag - point to the "sage" tag on the right hand side of the page and select "subscribe". – kini May 17 '12 at 18:03
4

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 *
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
  • This leaves me still wondering the original question "can I use a sage function within python?" (Distinct from "can I use a sage function within the special version of Python that is bundled with Sage"). And why on earth not? Seems like this doesn't scale well, if each module decrees that you can use it only in the special version of python that's bundled with it. – Don Hatch Jan 01 '20 at 23:33