0

I want to run a Java code, which is :

import org.python.util.PythonInterpreter;

public class PyConv {
    public static void main(String[] args){
        PythonInterpreter interpreter = new PythonInterpreter();
        interpreter.execfile("Test.py");
  }
}

And the Test.py file;

import pandas
import numpy

df = pd.read_csv("Myfile.csv", header=0)

But I would get an error:

Exception in thread "main" Traceback (most recent call last):
  File "Test.py", line 1, in <module>
    import pandas
ImportError: No module named pandas

So, How would one import the required module, to make the code run? And also I am using the Jython as a external jar in my java code. Is there any other way which would make my job simpler?

Yashwanth Remidi
  • 161
  • 1
  • 4
  • 13
  • Does `python Test.py` work? – SubOptimal Apr 12 '16 at 11:24
  • have you installed pandas package , if not use - pip install pandas – hemraj Apr 12 '16 at 11:53
  • It does work with my python interpreter but not working with jython. So, how to install it for jython since 'pip install .... ', does the installation in python libs not Jython. – Yashwanth Remidi Apr 12 '16 at 12:00
  • 2
    I don't think you can use numpy and pandas directly from Jython: http://stackoverflow.com/questions/19455100/can-i-run-numpy-and-pandas-with-jython – davidrmcharles Apr 12 '16 at 15:49
  • So, it is still not possible to call a .py file from java, using jython, if it has some external libraries imports. So is there any other method, besides jython I can use to call .py files from java ? – Yashwanth Remidi Apr 13 '16 at 06:55

0 Answers0