470,591 Members | 1,484 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

Using python libraries in a Java Program

Hi everyone,
I would like to know if it's possible to use python (libraries) in a
Java Program.
I do not want to use: Process proc = Runtime.getRuntime.exec(command)

I am basically looking for something like the "Reversed" version of
Jython.

Thanks in advance.
-gohaku
Jul 18 '05 #1
3 2018
gohaku wrote:
Hi everyone,
I would like to know if it's possible to use python (libraries) in a
Java Program.
I do not want to use: Process proc = Runtime.getRuntime.exec(command)

I am basically looking for something like the "Reversed" version of Jython.

Thanks in advance.
-gohaku

I think you can use Jython that way. Just compile your module to a
..class file using jythonc, then use it like any other class. If you want
to access python modules put "import org.python.modules.MODULENAME.*" in
your Java program.
Jul 18 '05 #2
Sam Roth wrote:
gohaku wrote:
Hi everyone,
I would like to know if it's possible to use python (libraries) in a
Java Program.
I do not want to use: Process proc = Runtime.getRuntime.exec(command)

I am basically looking for something like the "Reversed" version of
Jython.

Thanks in advance.
-gohaku

I think you can use Jython that way. Just compile your module to a
.class file using jythonc, then use it like any other class. If you want
to access python modules put "import org.python.modules.MODULENAME.*" in
your Java program.


For this to work though, the Python class must implement or extend a
Java interface/class. Otherwise a pure python class compiled to .class
has a very strange interface indeed.

Also, if the needed python module is a native one, or relies on native
code. you're out of luck.

Depending on the type of integration needed, and the type of module to
integrate. I see that you have 2 choices. Either build a simple JNI
module to embed the Python interprter in Java. Expose a few methods like
execfile and you have simple integration that allows you to call any
python module.

Tighter integration would be very difficult indeed. I am currently doing
the same thing, except in reverse (hosting the JVM inside python) and
its a pretty complicated task. I guess you could use my project to host
your whole program in Python, then make callbacks back into ptyhon code
to use the module. Then again, you could do the same using jython ...

Good luck,

Steve
Jul 18 '05 #3
You may look at JPE (Java Python Environment).

It is a Sourceforge project...

Dieter
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

36 posts views Thread by Tim Churches | last post: by
5 posts views Thread by Sridhar R | last post: by
6 posts views Thread by Chas Emerick | last post: by
29 posts views Thread by walterbyrd | last post: by
34 posts views Thread by Anthony Irwin | last post: by
reply views Thread by nadeemabdulhamid | last post: by
18 posts views Thread by Jens | last post: by
5 posts views Thread by hussainsaiger | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.