我正在尝试执行我的python脚本,它通过pip导入全局安装的模块。 (像nltk这样的模块)
以下是我的代码。
interpreter.execfile("/home/roy/eclipse-workspace/geospatial-analysis/src/main/resources/wordnet_util.py");
PyObject someFunc = interpreter.get("get_similarity");
PyObject result = someFunc.__call__(new PyString("Apple pie."), new PyString("Banana pie."));
Double realResult = (Double) result.__tojava__(Double.class);
我添加了python模块的路径,如
import sys
sys.path.append("/usr/local/lib/python2.7/dist-packages")
但是我收到以下错误,
*sys-package-mgr*: can't create package cache dir, '/usr/local/lib/python2.7/dist-packages/cachedir/packages'
Exception in thread "main" Traceback (most recent call last):
File "/home/roy/eclipse-workspace/geospatial-analysis/src/main/resources/wordnet_util.py", line 6, in <module>
from nltk import word_tokenize, pos_tag
File "/usr/local/lib/python2.7/dist-packages/nltk/__init__.py", line 18, in <module>
from __future__ import print_function, absolute_import
ImportError: No module named __future__
更新
我将sys.path.append(“/ usr / lib / python2.7”)添加到python文件中。它解决了上述错误。现在它找不到选择模块。
ImportError: No module named signal