Differences between revisions 5 and 10 (spanning 5 versions)
Revision 5 as of 2008-07-09 00:01:02
Size: 2664
Editor: OndrejCertik
Comment:
Revision 10 as of 2008-07-11 10:59:40
Size: 4879
Comment: add disclaimer about using the system python
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Create the `run_sage` bash script: '''Important''': One should note that this can cause various problems due to different python build options. Currently the script below does not work on OSX since Apple's python is compiled with ucs2 while Sage's Python is compiled with ucs4. If you encounter any bug or problem please state clearly that you are using the system's python since that configuration might contribute to the problem. The Sage people will attempt to reproduce the problem with vanilla Sage, but because there are a large number of distributions out there we cannot debug problems where we might not have access, so if you break Sage that way you get to keep the pieces ;-)

== Easy Way ==
Create this `s.py` python script:
Line 5: Line 9:
#! /bin/bash

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:
{{{
#!python
Line 45: Line 11:
import re
Line 46: Line 13:
Line 50: Line 16:
Line 59: Line 24:
Line 64: Line 28:
            "SAGE_SERVER": "http://www.sagemath.org/",
Line 67: Line 32:
def import_sageall():
    """
    Imports sage by "import sage.all".
    If it fails, write a helpful message and exit. After executing this method,
    you can be sure that sage just works, e.g you can do
    from sage.all import something
    without worrying.
    """
    try:
        import sage.all
    except ImportError, e:
        if re.match("(.*).so: cannot open shared object file: No such file or directory", e.message):
            # all seems to be just a LD_LIBRARY_PATH problem in 99% of cases
            print """\
"import sage.all" failed when importing an .so library, this is most probably
an LD_LIBRARY_PATH problem, please set your LD_LIBRARY_PATH and try again, e.g. execute:
LD_LIBRARY_PATH=%s/local/lib python %s""" % (os.environ.get("SAGE_ROOT", ""),
        sys.argv[0])
            sys.exit()
        else:
            # some other problem
            raise
Line 69: Line 55:
import_sageall()
Line 72: Line 58:
print x**2/3-log(x) e = x**2/3-log(x)
print e
print integrate(e, x)
Line 74: Line 62:
and run it like this: and try to run it:
Line 76: Line 65:
$ LD_LIBRARY_PATH="/home/ondra/ext/sage/local/lib" python s.py
Falling back to a hard coded sage server in misc/hg.py
$ python s.py
"import sage.all" failed when importing an .so library, this is most probably
an LD_LIBRARY_PATH problem, please set your LD_LIBRARY_PATH and try again, e.g. execute:
LD_LIBRARY_PATH=/home/ondra/ext/sage/local/lib python s.py
}}}
it tells you the exact command that you need to execute to make it work, so do it:
Line 79: Line 72:
{{{
$ LD_LIBRARY_PATH=/home/ondra/ext/sage/local/lib python s.py
Line 83: Line 78:
                                            3
                                           x
                              - x log(x) + -- + x
                                           9
Line 84: Line 83:
So as you can see from the above, all you have to do is to set the `root` keyword parameter in the script to point to your Sage installation and that's it. The script will tell you the correct command to run itself.

== Robust Way ==
Create the `run_sage` bash script:

{{{
#! /bin/bash
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
}}}

How to run Sage in a systemwide Python

Important: One should note that this can cause various problems due to different python build options. Currently the script below does not work on OSX since Apple's python is compiled with ucs2 while Sage's Python is compiled with ucs4. If you encounter any bug or problem please state clearly that you are using the system's python since that configuration might contribute to the problem. The Sage people will attempt to reproduce the problem with vanilla Sage, but because there are a large number of distributions out there we cannot debug problems where we might not have access, so if you break Sage that way you get to keep the pieces ;-)

Easy Way

Create this s.py python script:

   1 import os
   2 import re
   3 import sys
   4 def set_paths(root="/home/ondra/ext/sage"):
   5     """
   6     Set paths necessary to import sage.
   7     root ... the path to your Sage installation
   8     """
   9     python_path = [
  10         root+"/local/lib/python",
  11         root+"/local/lib/python2.5/lib-dynload",
  12         root+"/local/lib/python2.5/site-packages",
  13             ]
  14     sys.path = python_path + sys.path
  15     paths = {
  16             "SAGE_ROOT": root,
  17             "SAGE_LOCAL": root+"/local",
  18             "DOT_SAGE": "~/.sage/",
  19             "SAGE_SERVER": "http://www.sagemath.org/",
  20             "PATH": root+"/local/bin:"+os.environ["PATH"],
  21             }
  22     os.environ.update(paths)
  23 def import_sageall():
  24     """
  25     Imports sage by "import sage.all".
  26     If it fails, write a helpful message and exit. After executing this method,
  27     you can be sure that sage just works, e.g you can do
  28     from sage.all import something
  29     without worrying.
  30     """
  31     try:
  32         import sage.all
  33     except ImportError, e:
  34         if re.match("(.*).so: cannot open shared object file: No such file or directory", e.message):
  35             # all seems to be just a LD_LIBRARY_PATH problem in 99% of cases
  36             print """\
  37 "import sage.all" failed when importing an .so library, this is most probably
  38 an LD_LIBRARY_PATH problem, please set your LD_LIBRARY_PATH and try again, e.g. execute:
  39 LD_LIBRARY_PATH=%s/local/lib python %s""" % (os.environ.get("SAGE_ROOT", ""),
  40         sys.argv[0])
  41             sys.exit()
  42         else:
  43             # some other problem
  44             raise
  45 set_paths()
  46 import_sageall()
  47 from sage.all import *
  48 var("x")
  49 e = x**2/3-log(x)
  50 print e
  51 print integrate(e, x)

and try to run it:

$ python s.py
"import sage.all" failed when importing an .so library, this is most probably
an LD_LIBRARY_PATH problem, please set your LD_LIBRARY_PATH and try again, e.g. execute:
LD_LIBRARY_PATH=/home/ondra/ext/sage/local/lib python s.py

it tells you the exact command that you need to execute to make it work, so do it:

$ LD_LIBRARY_PATH=/home/ondra/ext/sage/local/lib python s.py
                                   2
                                  x
                                  -- - log(x)
                                  3
                                            3
                                           x
                              - x log(x) + -- + x
                                           9

So as you can see from the above, all you have to do is to set the root keyword parameter in the script to point to your Sage installation and that's it. The script will tell you the correct command to run itself.

Robust Way

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