0

我正在尝试执行我的 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
4

0 回答 0