473,769 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)
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.s o.1.0" "libpython2.4.s o.1.0"
"libpython2.3.s o.1.0"))
(:windows (:or "python25.d ll" "python24.d ll" "python23.d ll") )
(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.as d
; 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_cla ss import timeit
File "sage_timeit_cl ass.pyx", line 3, in sage.misc.sage_ timeit_class
; (sage/misc/sage_timeit_cla ss.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.genutil s 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,s ys.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'
Oct 29 '08 #1
1 2793
["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

220
19156
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 any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
699
34160
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 capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
58
4027
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 miss my macros whenever I try to use it...
176
8182
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? Thank you, -- greetz tom
118
6741
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 hated it, having learned C++ a few years prior. They didn't teach Lisp at all and instead expected us to learn on our own. I wasn't aware I had to uproot my thought process to "get" it and wound up feeling like a moron. In learning Python I've...
267
10829
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 http://www.artima.com/weblogs/viewpost.jsp?thread=147358
852
28688
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 my general education. Mark
206
8372
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 footprint which says: "Indeed, one often hears arguments against building exibility into an engineered sys- tem. For example, in the philosophy of the computer language Python it is claimed: \There should be one|and preferably only one|obvious...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9997
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.