我是Jython的新手,我正在尝试使用Java中的Jython运行python类。但是我遇到了一些问题。
我定义的 Java 类:
public class DemistoCalls {
PythonInterpreter interpreter = null;
public DemistoCalls()
{
PythonInterpreter.initialize(System.getProperties(),
System.getProperties(), new String[0]);
this.interpreter = new PythonInterpreter();
}
void execfile( final String fileName )
{
this.interpreter.execfile(fileName);
}
PyInstance createClass( final String className, final String opts )
{
return (PyInstance) this.interpreter.eval(className + "(" + opts + ")");
}
public static void main(String[] args) {
DemistoCalls demistoCalls = new DemistoCalls();
demistoCalls.execfile("C:\Users\AlokNath\Desktop\Demisto_Project\demisto-py-master\demisto\SimpleConnect.py");
}
}
我尝试运行 SampleConnect.py 文件:
import sys
sys.path.append("C:UsersAlokNathDesktopDemisto_Projectdemisto-py-
masterdemisto")
import demisto
运行java文件时,我收到此错误:
File "C:UsersAlokNathDesktopDemisto_Projectdemisto-py-masterdemistoSimpleConnect.py", line 3, in <module>
import demisto
ImportError: No module named demisto
尽管我已经在系统路径中定义了"demisto"模块,并检查了python中的系统路径是否包含指向Jython 2.7.lb2库的适当路径。我不确定我哪里出错了。任何帮助,不胜感激。
问候 阿洛克
我找到了导入错误问题的解决方案。我们需要将缺少的模块复制到"modeler-installation/lib/jython/Lib"下的"site-packages"文件夹中。这将解决依赖关系问题。