我正在尝试通过使用PythonInterpreter在Java代码(在Netbeans中)中使用来自python代码的函数,并且当python代码中没有任何导入的包时,它工作得很好,但是在我的代码中需要一个包导入“ tweepy”时出现错误:
import org.python.util.PythonInterpreter;
import org.python.core.*;
public class test {
public static void main(String[] args) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("python_code.py");
PyFunction getCountFunc = (PyFunction)interpreter.get("funcTw", PyFunction.class);
PyObject pyCount = getCountFunc.__call__(new PyString("Test String"));
String realResult = (String) pyCount.__tojava__(String.class);
}
}
try:
import json
except ImportError:
import simplejson as json
import tweepy
import sys
def funcTw(str):
# function body ...
Exception in thread "main" Traceback (most recent call last):
File "python_code.py", line 7, in <module>
import tweepy
ImportError: No module named tweepy
那么如何在Java中导入tweepy?我已经通过python
安装了它