我正在从名为PyInterpreter的Java类中运行一个名为diagnostics.py的python程序,该程序初始化jython PythonInterpreter对象和要使用的文件,并且可以从该python程序运行方法。 我的python程序如下所示:
import datetime
import psutil
class HeartbeatGenerator:
...
当我尝试运行该程序时,出现错误:
Exception in thread "main" Traceback (most recent call last):
File "../../../eclipse-workspace/Diagnostics/diagnostics.py", line 2, in
import datetime
ImportError: No module named datetime
我已经使用pip安装了datetime和psutil,它们位于/usr/local/bin/python3.7/site-packages以及/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-包。 我还从该位置复制了必要的文件并将其粘贴到我的jython.2.5.3 / lib / site-packages中,并且在我的PyInterpreter文件中,我尝试设置python.home和python.path的系统属性,如下所示:
public PyInterpreter()
{
Properties props = System.getProperties();
props.setProperty("python.home", "/usr/local/lib/python3.7");
props.setProperty("python.path", "/usr/local/lib/python3.7/site-packages");
System.out.print(props);
PythonInterpreter.initialize(System.getProperties(),
props,
new String[0]);
this.interpreter = new PythonInterpreter();
}
但是无论我将sys属性设置为什么,我仍然会遇到相同的错误。 现在,它仅在导入datetime的行上,但是我知道如果我首先import psutil ,它也会在该行上中断。 有任何想法吗?