By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,304 Members | 3,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,304 IT Pros & Developers. It's quick & easy.

Using python libraries in a Java Program

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.