2016-07-31 6 views
0

私はPythonスクリプトを持っています。私はJythonを使って同じJavaプロセスを実行しています。pymongoという名前のモジュールがありません - Jython

データベース - MongoDBの

のpom.xml

<dependency> 
    <groupId>org.python</groupId> 
    <artifactId>jython-standalone</artifactId> 
    <version>2.7.0</version> 
</dependency> 

public String execute(String val) throws FileNotFoundException, 
      ScriptException { 
     ClassLoader classLoader = getClass().getClassLoader(); 
     InputStream is = (InputStream) classLoader 
       .getResourceAsStream("my.py"); 

     PythonInterpreter interpreter = new PythonInterpreter(); 
     interpreter.execfile(is); 

     PyObject someFunc = interpreter.get("myFunc"); 
     PyObject result = someFunc.__call__(new PyString(val)); 
     String realResult = (String) result.__tojava__(String.class); 
     return realResult; 
    } 

私はPythonスクリプトを実行し、my.pyは、私はエラー

の下に取得するJavaプロセス
File "<iostream>", line 3, in <module> 
ImportError: No module named pymongo 

答えて

0

私は以下のようなモジュールをインポートすることで解決: -

PythonInterpreter interpreter = new PythonInterpreter(null, new PySystemState()); 
    PySystemState sys = interpreter.getSystemState(); 
    sys.path.append(new PyString("\\python_modules\\pymongo-3.3.0-cp26-none-win_amd64.whl")); 

私はhereからpymongoモジュールをダウンロードしています。 上記は私のために働いた、この方法で私たちはjythonを通してモジュールをインポートすることができます。

関連する問題