Ask Your Question

randomness431's profile - activity

2016-10-17 20:24:48 +0100 received badge  Good Question (source)
2014-01-16 22:00:20 +0100 received badge  Nice Question (source)
2013-04-23 08:58:46 +0100 received badge  Famous Question (source)
2013-04-16 20:02:39 +0100 received badge  Student (source)
2012-10-11 14:58:40 +0100 received badge  Notable Question (source)
2012-04-25 04:12:01 +0100 received badge  Popular Question (source)
2011-07-08 10:00:11 +0100 commented answer Using Sage in a Python CGI script

Setting the path works, but that requires me to add a shell script to call this script. I tried your suggestion of putting #!path/to/sage -python as the first line instead and running it as ./factor.cgi 2006 and I get this now: ./factor.cgi: line 2: import: command not found ./factor.cgi: line 3: import: command not found ./factor.cgi: line 5: syntax error near unexpected token `from' ./factor.cgi: line 5: `from sage.all import *'

2011-07-07 17:19:00 +0100 asked a question Using Sage in a Python CGI script

I am writing cgi scripts in python that use sage. I have been researching for weeks and even the python and sage websites say use: "from sage.all import *" in your python script, and have "#!/usr/bin/env sage -python" as the first line of the script.

Here is the exact quote from sagemath faq on what to do: " The following standalone Sage script factors integers, polynomials, etc:

#!/usr/bin/env sage -python

import sys
from sage.all import *

if len(sys.argv) != 2:
    print "Usage: %s <n>"%sys.argv[0]
    print "Outputs the prime factorization of n."

print factor(sage_eval(sys.argv[1]))

In order to use this script, your SAGE_ROOT must be in your PATH."

I made the cgi file exactly as is, and put onto my web server (Apache running CentOS), with sage and python installed. When I try to run this file (named factor.cgi) through the bash terminal I do:

$ ./factor.cgi 2006
/usr/bin/env: sage -python: No such file or directory

Any help on what I should do to make this script work would be appreciated.