473,381 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 software developers and data experts.

calling python from lisp

Dear all,

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)

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 *
>>integrate(1/z, 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

(cffi:define-foreign-library python-library
(:darwin (:framework "Python"))
(:unix (:or "libpython2.5.so.1.0" "libpython2.4.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

Help would be greatly appreciated.


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">
; loading system definition from /home/martin/.sbcl/systems/cffi.asd into
; registering #<SYSTEM CFFI {AAF00B1}as CFFI
; loading system definition from /home/martin/.sbcl/systems/babel.asd into
; registering #<SYSTEM BABEL {AC6A4D9}as BABEL
; loading system definition from /home/martin/.sbcl/systems/alexandria.asd into
; loading system definition from
; /home/martin/.sbcl/systems/trivial-features.asd into #<PACKAGE "ASDF0">


; compilation unit finished
; caught 11 STYLE-WARNING conditions
; printed 4 notes
* (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>
; "/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
; "/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)
; "/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
; "/home/martin/Documents/sage-3.1.4/local/lib/python2.5/site-packages/sage/misc/interpreter.py",
; line 99, in <module>
import IPython.ipapi
; "/home/martin/Documents/sage-3.1.4/local/lib/python2.5/site-packages/IPython/__init__.py",
; line 57, in <module>
; "/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
; "/home/martin/Documents/sage-3.1.4/local/lib/python2.5/site-packages/IPython/genutils.py",
; line 116, in <module>
Term = IOTerm()
; "/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)
; "/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'
Oct 29 '08 #1
1 2748
["Followup-To:" header set to comp.lang.lisp.]
On 2008-10-29, Martin Rubey <ax******@yahoo.dewrote:
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 proted to CLPython, it gets compiled,
and you can call it much more directly from other Lisp code.
Oct 29 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
by: Svein Ove Aas | last post by:
Is anyone working on a python-to-native compiler? I'd be interested in taking a look. Come to think of it, is anyone working on a sexpr-enabled version of Python, or anything similar? I really...
by: Thomas Reichelt | last post by:
Moin, short question: is there any language combining the syntax, flexibility and great programming experience of Python with static typing? Is there a project to add static typing to Python? ...
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely...
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at...
by: Mark Tarver | last post by:
How do you compare Python to Lisp? What specific advantages do you think that one has over the other? Note I'm not a Python person and I have no axes to grind here. This is just a question for...
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.