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: 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: Any help on what I should do to make this script work would be appreciated. |

The problem seems to be that and then the script will know explicitly which Sage installation to use.
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 *'
randomness431 (Jul 08 '11)
That's strange. Where is your Sage installed? Could you post your factor.cgi script on something like pastebin.com? My Sage is installed at "/opt/sage", so I'd put "#!/opt/sage/sage -python" at the top of my script.
Mike Hansen (Jul 09 '11) |

Unfortunately, Linux passes the entire rest of the shebang command line as a single argument to the shebang executable. Therefore, if you use "#!/usr/bin/env prog", then it's impossible to pass any arguments to prog. My solution was to change it to and write a wrapper script called sage-python containing |

Asked: **Jul 07 '11**

Seen: **1,029 times**

Last updated: **May 29 '13**

powered by ASKBOT version 0.7.22

Copyright Sage, 2010. Some rights reserved under creative commons license.