Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Ruby-Python; using python from within ruby

Reply
Thread Tools

Ruby-Python; using python from within ruby

 
 
Norjee
Guest
Posts: n/a
 
      07-30-2005
At the moment I'm looking at rails, it seems like a great framework.
The only downside it has is its rather limited availability of 3rd
party libraries. At the moment there are at least two libraries I need
that are available to python but not to ruby (search engine, either
xapian or lucene( python has bindings to both, ruby has neither), pydns
and another custom python script)

After looking for a solution I came across ruby-python
(http://raa.ruby-lang.org/project/ruby-python/). Sadly enough it is a
little bit outdated. It seems to need ruby 2.6 and python 1.5 while
I'm using ruby 1.82 and python 2.4. I tried looking into the source
code, changing reference to python 1.5 to python 2.4, changed
PyObject_HEAD_INIT(&PyType_Type) to PyObject_HEAD_INIT(NULL) and set
ob_type to &PyType_Type in the init method (the new gcc compiler
doesn't like non constant elements outside function calls) and even got
it to compile. However, this is about as far as my knowledge of C goes,
and i end up with a segmentation fault. Thus somewhere there's a
pointer or reference not pointing to the right spot. I have absolutely
no clue how to solve this.

Are there any other libraries which allow ruby to execute python code,
or has anybody got ruby-python to work with recent versions of both
ruby and python?
If there is no solution i could of course shell execution to run some
python scripts, using that output, but I'd rather not do this as
it'll create quite some messy interaction. Moreover, I think having
ruby able to run use python libraries would definitely help others to
adapt to using ruby, as I'm sure that the lack of libraries is
holding them back to use ruby, just as it does for me. Being able to
use at least a part of the libraries available to python gives ruby a
lot more libraries, with just having one wrapper library.

 
Reply With Quote
 
 
 
 
Jim Freeze
Guest
Posts: n/a
 
      07-30-2005
* Norjee <(E-Mail Removed)> [2005-07-30 23:01:02 +0900]:

> At the moment I'm looking at rails, it seems like a great framework.
> The only downside it has is its rather limited availability of 3rd
> party libraries. At the moment there are at least two libraries I need
> that are available to python but not to ruby (search engine, either
> xapian or lucene( python has bindings to both, ruby has neither), pydns
> and another custom python script)


You may want to check out Ruby Odeum:

http://www.zedshaw.com/projects/ruby_odeum/
http://www.zedshaw.com/projects/ruby...rformance.html

--
Jim Freeze


 
Reply With Quote
 
 
 
 
Norjee
Guest
Posts: n/a
 
      07-30-2005
I'll take a look at odeum. Though that'll only solve a part of the
things i've been trying (though i have to admit, it'd be the most
complicated one). But still i'd really like to have the ability to use
python code inside ruby, just for the simple reason to extend the
availabilty of 3rd party libraries to ruby.

 
Reply With Quote
 
Lothar Scholz
Guest
Posts: n/a
 
      07-30-2005
Hello Norjee,

N> If there is no solution i could of course shell execution to run some
N> python scripts, using that output, but I'd rather not do this as
N> it'll create quite some messy interaction. Moreover, I think having
N> ruby able to run use python libraries would definitely help others to
N> adapt to using ruby, as I'm sure that the lack of libraries is
N> holding them back to use ruby, just as it does for me. Being able to
N> use at least a part of the libraries available to python gives ruby a
N> lot more libraries, with just having one wrapper library.

Instead of trying to generate something generic you maybe should
simply write a C extension that includes python.h and ruby.h and wrap
the API calls. If it is not very performance critical (i really think
it is not) you can simply generate the connectivity by passing string
arguments from one side to the other, together with a little parameter
encoding/decoding.

And yes, this requires C and gives you a good way to learn more about
it. Having knowlegde of C is IMHO an absolute "must have" for every
programmer.



--
Best regards, emailto: scholz at scriptolutions dot com
Lothar Scholz http://www.ruby-ide.com
CTO Scriptolutions Ruby, PHP, Python IDE 's




 
Reply With Quote
 
Norjee
Guest
Posts: n/a
 
      07-30-2005
I kind of got the ruby-python module to work! Sadly enough, I'm still
only vaguely aware of how it works. And I haven't thoroughly tested
things.

But for now, it appears to be quite usable for my situation. I can
execute my custom python modules from within Ruby, what more could I
wish to achieve

 
Reply With Quote
 
Norjee
Guest
Posts: n/a
 
      07-30-2005
I kind of got the ruby-python module to work! Sadly enough, I'm still
only vaguely aware of how it works. And I haven't thoroughly tested
things.

But for now, it appears to be quite usable for my situation. I can
execute my custom python modules from within Ruby, what more could I
wish to achieve

 
Reply With Quote
 
Esteban Manchado Velázquez
Guest
Posts: n/a
 
      07-31-2005
On Sun, Jul 31, 2005 at 03:41:03AM +0900, Norjee wrote:
> I kind of got the ruby-python module to work! Sadly enough, I'm still
> only vaguely aware of how it works. And I haven't thoroughly tested
> things.


Do you mind posting it somewhere? I'm sure many people would find it
interesting...

Is the original author definitely not interested in maintaining the mo=
dule?
Perhaps with a little help from other people?

--=20
Esteban Manchado Vel=E1zquez <(E-Mail Removed)> - http://www.foton.es
EuropeSwPatentFree - http://EuropeSwPatentFree.hispalinux.es


 
Reply With Quote
 
Norjee
Guest
Posts: n/a
 
      07-31-2005
I already send my changes to the original author. It weren't really ig
changes. Only changing references to python1.5 to python2.4. Initialize
two PyObjects in the init method instead of doing that in their
definition, and finally i removed a check for duplicate modules, as it
marked all objects as duplicates. Especial the removal of this check
is, ofcourse, a bad thing.

To get it to compile in windows i also had to change to sequence in
which the headers were included. But under windows it nly works
Partially. I can exeucte python statements with the methods created for
the Py object (Py.eval for example), trying to work on a real Python
module (Py::Sys for example) crashes the whole thing.

As i said, i'm not really a programmer, and to have a full understandig
of the code one would need to understand both the ruby and python way
of interacting with C. As i know neither, i'm not the person to update
the module.

 
Reply With Quote
 
Norjee
Guest
Posts: n/a
 
      07-31-2005
I already send my changes to the original author. It weren't really big

changes. Only changing references to python1.5 to python2.4. Initialize

two PyObjects in the init method instead of doing that in their
definition, and finally I removed a check for duplicate modules, as it
marked all objects as duplicates. Especial the removal of this check
is, of course, a bad thing.
To get it to compile in windows I also had to change to sequence in
which the headers were included. But under windows it only works
partially. I can execute python statements with the methods created for

the Py object (Py.eval for example), trying to work on a real Python
module (Py::Sys for example) crashes the whole thing.
As I said, I'm not really a programmer, and to have a full
understanding
of the code one would need to understand both the ruby and python way
of interacting with C. As I know neither, I'm not the person to
update
the module.

 
Reply With Quote
 
Lyndon Samson
Guest
Posts: n/a
 
      08-02-2005
This seems to work for me, Windows only though...

require 'Win32API'

PyInitialize =3D Win32API.new("python24", "Py_Initialize", [], 'V')
PyRun_SimpleString =3D Win32API.new("python24", "PyRun_SimpleString", ['P']=
, 'V')
Py_Finalize =3D Win32API.new("python24", "Py_Finalize", [], 'V')

pythonSrc =3D <<EOF

from time import time,ctime
print 'Hello at ',ctime(time())

EOF

PyInitialize.call()
PyRun_SimpleString.call(pythonSrc)
Py_Finalize.call()


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling Ruby from within Ruby under Windows Ronald Fischer Ruby 2 06-22-2007 09:12 AM
Using Python within a Python application. Michael B. Trausch Python 0 11-02-2006 02:41 PM
Ruby within Ruby Mike Zink Ruby 12 08-27-2006 03:36 AM
#!/usr/bin/ruby , #!/usr/bin/ruby -w , #!/usr/bin/ruby -T?, #!/usr/bin/ruby -T1... anne001 Ruby 1 04-23-2006 03:02 PM
Using values within arrays within a hash to gsub into an input word... Abe Ruby 2 04-15-2006 08:16 PM



Advertisments