I'm trying to call from common lisp functions written for Sage
(www.sagemath.org), which in turn is written in python. To do so, I tried
http://common-lisp.net/project/python-on-lisp/. It was quite easy to get it to
run and do some simple things with python.
However, I was unable to get sage to run within it.
If I start my local python 2.5 and follow (roughly)
http://www.sagemath.org/doc/tut/node55.html
it works nicely:
martin@rubey-laptop:~/Documents/sage-3.1.4/local/bin$ . ./sage-env
martin@rubey-laptop:~/Documents/sage-3.1.4/local/bin$ /usr/bin/python
Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> from sage.all import *
>>> var('z')
z
>>> integrate(1/z, z)
log(z)
>>>
But not so from within python-on-lisp. Below the complete log. But actually,
the first warning occurs already when importing sys (I have little python
experience and no idea what sys contains)
sys:1: RuntimeWarning: Python C API version mismatch for module pol: This Python has API version 1013, module pol has version 1011.
As far as I understand python on lisp, it provides an interface to the python
library:
(cffi:define-foreign-library python-library
(:darwin (:framework "Python"))
(:unix (:or "libpython2.5.so.1.0" "libpython2.4.so.1.0"
"libpython2.3.so.1.0"))
(:windows (:or "python25.dll" "python24.dll" "python23.dll") )
(t (:default "libpython")))
Sage comes with it's own python, however, without a library. On the otherhand,
above I demonstrated that sage also works with the python interpreter that
comes with kubuntu. (maybe it needs the interpreter, and the library is not
sufficient?)
Help would be greatly appreciated.
Martin
martin@rubey-laptop:~/Documents/sage-3.1.4/local/bin$ sbcl
This is SBCL 1.0.11.debian, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (asdf:operate 'asdf:load-op :pythononlisp)
; loading system definition from /home/martin/.sbcl/systems/pythononlisp.asd
; into #<PACKAGE "ASDF0">
; registering #<SYSTEM #:PYTHONONLISP {A98B239}> as PYTHONONLISP
; loading system definition from /home/martin/.sbcl/systems/cffi.asd into
; #<PACKAGE "ASDF0">
; registering #<SYSTEM CFFI {AAF00B1}> as CFFI
; loading system definition from /home/martin/.sbcl/systems/babel.asd into
; #<PACKAGE "ASDF0">
; registering #<SYSTEM BABEL {AC6A4D9}> as BABEL
; loading system definition from /home/martin/.sbcl/systems/alexandria.asd into
; #<PACKAGE "ASDF0">
; registering #<SYSTEM :ALEXANDRIA {ADE1199}> as ALEXANDRIA
; loading system definition from
; /home/martin/.sbcl/systems/trivial-features.asd into #<PACKAGE "ASDF0">
; registering #<SYSTEM TRIVIAL-FEATURES {AF0F739}> as TRIVIAL-FEATURES
...<snip>
; compilation unit finished
; caught 11 STYLE-WARNING conditions
; printed 4 notes
NIL
* (py::py-repl)
Welcome to the Python-on-lisp REPL emulator - enter on a blank line to quit
import sys
sys:1: RuntimeWarning: Python C API version mismatch for module pol: This Python has API version 1013, module pol has version 1011.
>>> If you can see this, Python is loaded and working
from sage.all import *
>>> Traceback (most recent call last):
File "<string>", line 9, in <module>
File
; "/home/martin/Documents/sage-3.1.4/local/lib/python2.5/site-packages/sage/all.py",
; line 58, in <module>
from sage.misc.all import * # takes a while
File
; "/home/martin/Documents/sage-3.1.4/local/lib/python2.5/site-packages/sage/misc/all.py",
; line 16, in <module>
from sage_timeit_class import timeit
File "sage_timeit_class.pyx", line 3, in sage.misc.sage_timeit_class
; (sage/misc/sage_timeit_class.c:523)
File
; "/home/martin/Documents/sage-3.1.4/local/lib/python2.5/site-packages/sage/misc/sage_timeit.py",
; line 12, in <module>
import timeit as timeit_, time, math, preparser, interpreter
File
; "/home/martin/Documents/sage-3.1.4/local/lib/python2.5/site-packages/sage/misc/interpreter.py",
; line 99, in <module>
import IPython.ipapi
File
; "/home/martin/Documents/sage-3.1.4/local/lib/python2.5/site-packages/IPython/__init__.py",
; line 57, in <module>
__import__(name,glob,loc,[])
File
; "/home/martin/Documents/sage-3.1.4/local/lib/python2.5/site-packages/IPython/ipstruct.py",
; line 22, in <module>
from IPython.genutils import list2dict2
File
; "/home/martin/Documents/sage-3.1.4/local/lib/python2.5/site-packages/IPython/genutils.py",
; line 116, in <module>
Term = IOTerm()
File
; "/home/martin/Documents/sage-3.1.4/local/lib/python2.5/site-packages/IPython/genutils.py",
; line 112, in __init__
self.cout = IOStream(cout,sys.stdout)
File
; "/home/martin/Documents/sage-3.1.4/local/lib/python2.5/site-packages/IPython/genutils.py",
; line 80, in __init__
self.flush = stream.flush
AttributeError: Sout instance has no attribute 'flush'
Maybe those functions will work under CLPython?
CLPython is different from python-on-lisp; it's front-end for Lisp that
understands Python syntax, and provides Python run-time support.
If the Python code can be proted to CLPython, it gets compiled,
and you can call it much more directly from other Lisp code.
> ["Followup-To:" header set to comp.lang.lisp.]
> On 2008-10-29, Martin Rubey <axio...@yahoo.de> wrote:
> > Dear all,
> >
> > I'm trying to call from common lisp functions written for Sage
> > (www.sagemath.org), which in turn is written in python.
>
> Maybe those functions will work under CLPython?
>
> CLPython is different from python-on-lisp; it's front-end for Lisp that
> understands Python syntax, and provides Python run-time support.
>
> If the Python code can be ported to CLPython, it gets compiled,
> and you can call it much more directly from other Lisp code.
No, Sage contains a HUGE amount of code.
Martin
> No, Sage contains a HUGE amount of code.
>
> Martin
And most of it isn't written in python.
In this particular example factor, is probably provided by maxima
which is written in CL.
This means you are using lisp to call python to call lisp.
There's probably an easier way to go about doing this.....
> On 29 Oct, 07:08, Martin Rubey <axiom...@yahoo.de> wrote:
>
> > No, Sage contains a HUGE amount of code.
> >
> > Martin
>
> And most of it isn't written in python.
That's correct. However, those things that interest me most, are.
> In this particular example factor, is probably provided by maxima which is
> written in CL.
Well, the point of sage is that it contains wrappers to *many* systems. And
maxima is probably the only sub system I'm not too interested in calling, since
I'd like to call it from FriCAS.
But the combinatorics part, for example, would be very nice to have.
> There's probably an easier way to go about doing this.....
No. If I want access to sage, I'll have to deal with python.
Martin