Using python libraries in a Java Program

G

gohaku

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
 
S

Sam Roth

gohaku said:
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.
 
S

Steve Menard

Sam said:
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
 
D

Dieter Maurer

You may look at JPE (Java Python Environment).

It is a Sourceforge project...

Dieter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,661
Latest member
sxarexu

Latest Threads

Top