ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 07 Mar 2013 13:24:57 -0600Sage/Cython compile embedded Cython with Sage importhttp://ask.sagemath.org/question/9119/sagecython-compile-embedded-cython-with-sage-import/Hi,
I was wondering how you can compile a Sage .pyx file into an embedded Cython .c file and compile it with gcc to create a standalone executable?
I tried:
sage -cython --embed filename.pyx
gcc filename.c -I/path/to/python -lpython2.7
but when I run the program it gives me the following error:
from sage.all import *
ImportError: No module named sage.all
Thanks!
DandaliuThu, 28 Jun 2012 11:04:34 -0500http://ask.sagemath.org/question/9119/sage version of python's execfilehttp://ask.sagemath.org/question/9894/sage-version-of-pythons-execfile/What is the sage analogue of python's "execfile()"? How do I ask sage to preprocess and execute a text file full of sage commands?
Up till now I've just been using execfile() on the sage command line prompt, because that's what I do in python sometimes. However I just learned the hard way that this is the wrong thing to do; it misses a vital preprocessing step. For example, if I ask for the type of 1/2 on the sage command line, the following happens:
sage: print type(1/2)
<type 'sage.rings.rational.Rational'>
Great! that's what I want. However if I put the following into the file "uhoh.py":
print type(1/2)
and then I issue the following command on the sage command line:
execfile("uhoh.py")
then I get the output
<type 'int'>
Yes, the integer 1/2. I want the last hour of debugging time back.
Of course what's happening is that the text file is being interpreted in pure python, in which 1/2 really does represent an integer division. What is the right thing to do here, rather than execfile()?Benjamin YoungThu, 07 Mar 2013 13:24:57 -0600http://ask.sagemath.org/question/9894/location of sage -python executablehttp://ask.sagemath.org/question/8182/location-of-sage-python-executable/I wanted to know the path of the python interpreter that sage uses, so I executed
sage -python
Python 2.6.4 (r264:75706, Jun 20 2011, 12:34:18)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/Users/tjfulle/Local/math/sage/darwin/local/bin/python'
Then, I navigate to /Users/tjfulle/Local/math/sage/darwin/local/bin to call the interpreter that sage uses directly:
./python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/Users/tjfulle/Local/math/sage/darwin/local/bin/python'
The output from sys.executable is the same for each case, but clearly, the two interpreters are different, for `sage -python`, the interpreter is Python 2.6.4 and for `/Users/tjfulle/Local/math/sage/darwin/local/bin/python` the interpreter is Python 2.6.1.
Am I missing something? Which python interpreter is being used when I type sage -python?
When performing the same exercise on my redhat machine, when I execute `/home/tjfulle/Local/math/sage/redhat/local/bin/python` it returns
./python: error while loading shared libraries: libpython2.6.so.1.0:
cannot open shared object file: No such file or directory
I'd like to use the python built in with sage, but call it directly bypassing the sage -python layer. Is this possible?
Tim FullerWed, 22 Jun 2011 08:28:32 -0500http://ask.sagemath.org/question/8182/