5

i'm trying to using function from python code in java code (in Netbeans) by using PythonInterpreter and it worked fine when there is no any imported package in python code, but in my code where there is a package is need to import "tweepy" i got an error:

java code:

  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 code (python_code.py):

try:
  import json
except ImportError:
  import simplejson as json

import tweepy
import sys


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

error when run java code:

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

so how can i import tweepy in java?? I already has installed it by python

s99
  • 119
  • 1
  • 1
  • 8

0 Answers0