Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved import org.python / working with jython and java?

Tags:

python

jython

I'm using Eclipse and I"m trying to create a java program that can run my python code. I'm following the guidelines on this page: http://jythonpodcast.hostjava.net/jythonbook/en/1.0/JythonAndJavaIntegration.html#using-jython-within-java-applications

But when I include these statements at the top:

package org.jython.book.util;

import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.util.PythonInterpreter;

I receive a message saying "The import org.python cannot be resolved." Any suggestions on how to fix this?

Thank you so much!!

like image 871
NSP Avatar asked May 30 '11 17:05

NSP


People also ask

Can Jython use Python libraries?

Jython does *not* support third-party Python libraries that use extensions written in C. This means that popular Python libraries like numpy, scipy and scikit-learn will not work in Jython (and, for this reason, will not work in Processing.py).

How do I import libraries into Jython?

We can import any java package or class in Jython, just as we do in a Java program. The following example shows how the java. util packages are imported in Python (Jython) script to declare an object of the Date class. Save and run the above code as UtilDate.py from the command line.

Can I use Java and Python together?

The seamless interaction between Python and Java allows developers to freely mix the two languages both during development and in shipping products.


1 Answers

  1. In the Package Explorer (on the left), right click on your Java project and select Properties.
  2. In the treeview on the left, select Java Build Path.
  3. Select the Libraries tab.
  4. Select Add External JARs...
  5. Browse to your Jython installation (C:\jython2.5.2 for me), and select jython.jar. Click OK.
  6. Click OK.
like image 180
Cam Jackson Avatar answered Nov 14 '22 22:11

Cam Jackson