s99*_*s99 5 python java jython pythoninterpreter
我正在尝试使用 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);
}
}
Run Code Online (Sandbox Code Playgroud)
try:
import json
except ImportError:
import simplejson as json
import tweepy
import sys
def funcTw(str):
# function body ...
Run Code Online (Sandbox Code Playgroud)
Exception in thread "main" Traceback (most recent call last):
File "python_code.py", line 7, in <module>
import tweepy
ImportError: No module named tweepy
Run Code Online (Sandbox Code Playgroud)
那么我怎样才能在java中导入tweepy呢?我已经用python安装了
| 归档时间: |
|
| 查看次数: |
691 次 |
| 最近记录: |