0

My objective is to invoke a python program from Java. For the same I am trying to use Jython (PythonInterpreter). When I try to run the standalone class, I am getting the following error in the console:

ImportError

My java code is very simple:

PythonInterpreter pythonInterpreter = new PythonInterpreter();
pythonInterpreter.execfile("C:\\Srikumar\\Learn\\python samples\\BankStatementAnalyser.py");

The Jython dependency added to POM is:

<dependency>
    <groupId>org.python</groupId>
    <artifactId>jython-standalone</artifactId>
    <version>2.7.1</version>
</dependency>

(plus all other misc. ones used in any basic spring boot application)

My python file starts like this:

import os
import pandas
from DataframeToExcel import getDataFrame
from datetime import datetime
import xlrd 

Note:

  1. I have installed Anaconda & I am able to run the python program as a standalone file from the Spyder IDE successfully.
  2. When I try to run a simple python program with just a print statement, the execution is successful, the issue is there only when additional modules/ packages are used (os,pandas,re etc).

Please advice me on a workaround for this. I have referred to all the similar questions related to the same issue, but they were different scenarios & also they were pretty old ones, hence finally decided to post a new question.

  • You cannot use Pandas with Jython. I believe the answers here are still valid: https://stackoverflow.com/q/36213908/407651 – mzjn Sep 01 '20 at 13:37
  • @mzjn - thank you for the response. Kindly note that I just need to trigger the py program execution which will eventually generate a excel sheet containing the required data and share the path with me. So any workaround solutions for accomplishing my task would be welcome. If not jython, is there any other API or util classes which can help me with this? – Srikumar Krishna Iyer Sep 02 '20 at 07:58
  • I have explained why you get an ImportError with pandas. Please edit the question to make it clearer what you want to do. – mzjn Sep 02 '20 at 08:36

0 Answers0