4

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);

  }
 }

Python コード (python_code.py):

try:
  import json
except ImportError:
  import simplejson as json

import tweepy
import sys


def funcTw(str):
 # function body ...

Java コード実行時のエラー:

Exception in thread "main" Traceback (most recent call last):
 File "python_code.py", line 7, in <module>
  import tweepy
ImportError: No module named tweepy

どうすればtweepyをJavaにインポートできますか?? 私はすでにPythonでインストールしています

4

0 に答える 0