Differences between revisions 4 and 5
Revision 4 as of 2008-07-08 23:45:12
Size: 3010
Editor: OndrejCertik
Comment:
Revision 5 as of 2008-07-09 00:01:02
Size: 2664
Editor: OndrejCertik
Comment:
Deletions are marked like this. Additions are marked like this.
Line 47: Line 47:
def set_paths():
    root = os.environ["SAGE_ROOT"]
def set_paths(root="/home/ondra/ext/sage"):
    """
    Set paths necessary to import sage.

    root ... the path to your Sage installation
    """
Line 50: Line 54:
            root+"/local/bin",
            root+"/local/lib/python2.5/site-packages/setuptools-0.6c8-py2.5.egg",
            root+"/local/lib/python2.5/site-packages/SQLAlchemy-0.4.3-py2.5.egg",
            root+"/local/lib/python",
            root+"/local/lib/python25.zip",
            root+"/local/lib/python2.5/plat-linux2",
            root+"/local/lib/python2.5/lib-tk",
            root+"/local/lib/python2.5/lib-dynload",
            root+"/local/lib/python2.5/site-packages",
            root+"/local/lib/python2.5/site-packages/IPython/Extensions"
        root+"/local/lib/python",
        root+"/local/lib/python2.5/lib-dynload",
        root+"/local/lib/python2.5/site-packages",
Line 61: Line 58:
    sys.path = python_path + sys.path
Line 62: Line 61:
            "SAGE_ROOT": root,
Line 67: Line 67:
    sys.path = python_path + sys.path
Line 70: Line 69:
Line 76: Line 76:
$ SAGE_ROOT=/home/ondra/ext/sage LD_LIBRARY_PATH="$SAGE_ROOT/local/lib/openmpi:$SAGE_ROOT/local/lib/:" python s.py $ LD_LIBRARY_PATH="/home/ondra/ext/sage/local/lib" python s.py 

How to run Sage in a systemwide Python

Create the run_sage bash script:

export SAGE_ROOT=/home/ondra/ext/sage

export SAGE_LOCAL=$SAGE_ROOT/local
export DOT_SAGE=~/.sage/
export PATH=$SAGE_ROOT/local/bin:$PATH

export LD_LIBRARY_PATH="$SAGE_ROOT/local/lib/openmpi:$SAGE_ROOT/local/lib/:"

export PYTHONPATH="$SAGE_ROOT/local/bin:$SAGE_ROOT/local/lib/python2.5/site-packages/setuptools-0.6c8-py2.5.egg:$SAGE_ROOT/local/lib/python2.5/site-packages/SQLAlchemy-0.4.3-py2.5.egg:$SAGE_ROOT/local/bin:$SAGE_ROOT/local/lib/python:$SAGE_ROOT/local/lib/python25.zip:$SAGE_ROOT/local/lib/python2.5/plat-linux2:$SAGE_ROOT/local/lib/python2.5/lib-tk:$SAGE_ROOT/local/lib/python2.5/lib-dynload:$SAGE_ROOT/local/lib/python2.5/site-packages:$SAGE_ROOT/local/lib/python2.5/site-packages/IPython/Extensions"

ipython

Then:

$ ./run_sage 
Python 2.5.1 (r251:54863, Mar 29 2008, 09:29:46) 
Type "copyright", "credits" or "license" for more information.

IPython 0.8.1 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: from sage.all import *
Falling back to a hard coded sage server in misc/hg.py

In [2]: var("x")                                                               
Out[2]: x

In [3]: x**2/4 + log(x)                                                        
Out[3]: log(x) + x^2/4

Now, if you don't want to setup so many things, create this s.py python script:

import os
import sys

def set_paths(root="/home/ondra/ext/sage"):
    """
    Set paths necessary to import sage.

    root ... the path to your Sage installation
    """
    python_path = [
        root+"/local/lib/python",
        root+"/local/lib/python2.5/lib-dynload",
        root+"/local/lib/python2.5/site-packages",
            ]
    sys.path = python_path + sys.path

    paths = {
            "SAGE_ROOT": root,
            "SAGE_LOCAL": root+"/local",
            "DOT_SAGE": "~/.sage/",
            "PATH": root+"/local/bin:"+os.environ["PATH"],
            }
    os.environ.update(paths)

set_paths()

from sage.all import *
var("x")
print x**2/3-log(x)

and run it like this:

$ LD_LIBRARY_PATH="/home/ondra/ext/sage/local/lib" python s.py 
Falling back to a hard coded sage server in misc/hg.py

                                   2
                                  x
                                  -- - log(x)
                                  3