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:
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:
- I have installed Anaconda & I am able to run the python program as a standalone file from the Spyder IDE successfully.
- 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.