2

I want to call python from the java code and pass the parameters to function in python. I have encapsulated a function in python. But the thing is I have also imported third party library sklearn in the python program. When I call a test program and pass the value to python, I am able to run the code. But when I tried using third party library such as sklearn and import in the python code, I got following error.

ImportError: No module named sklearn

I initialized object for the class PythonInterpreter and then using the following command, I included the path for the sklearn

this.interpreter.exec("import sys");
this.interpreter.exec("sys.path.append(\"/usr/local/lib/python2.7/dist-packages/sklearn\")");

Can anyone tell how to fix this problem? How to include third party library in the jython code and run the program?

Cory Kramer
119k19 gold badges176 silver badges233 bronze badges
asked Jun 19, 2015 at 11:15
1
  • remove sklearn after dist-packages Commented Jun 19, 2015 at 11:18

1 Answer 1

1

As sklearn depends on native CPython extensions, it currently won't work with Jython. However, keep an eye on JyNI (www.jyni.org), which will vastly improve this issue, but is still in an early state. Until JyNI is sufficiently mature, you can use one of the following projects:

They work by embedding the CPython interpreter and don't integrate with Jython. Still, if you depend on things like scikit or numpy, these are currently the only workable approaches to use your Python-code from Java.

answered Jun 30, 2015 at 15:27
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.