Search code examples
javapythonintellij-ideajython

Install Jython to use PythonInterpreter


I am trying to install Jython SDK into IntelliJ Java program. How can this be done? I installed Jython in default here: C:\jython2.7.2 and installed Python for Windows . Selecting this directory or its bin, gives this error

IntelliJ Picture

The selected directory is not a valid home for JDK.

Eventually, I want to utilize PythonInterpreter,

https://stackoverflow.com/a/8899042/15358601

PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("import sys\nsys.path.append('pathToModules if they are not there by default')\nimport yourModule");
// execute a function that takes a string and returns a string
PyObject someFunc = interpreter.get("funcName");
PyObject result = someFunc.__call__(new PyString("Test!"));
String realResult = (String) result.__tojava__(String.class);

Solution

  • You should be picking the JDK home dir, not the jython home dir. Example: C:\Program Files\Java\jdk1.8.0_112