2014-02-23 45 views
2

我知道有jython解決方案,但jython無法加載wtxl和rdxl;它只能加載有限的點子庫。所以我想寫JNI來做到這一點。我可以使用JNI調用Python庫嗎?

主要步驟如下: 的Java < - > JNI < - > C/C++ Python接口< - >本地Python環境< - >我html2excel Python庫

的問題是,它無法導入html2excel庫。我使用C/C++代碼,因爲這:

int to_excel(const std::string & htmlfile) 
{ 
    Py_Initialize(); 
    PyRun_SimpleString("import sys"); 
    PyRun_SimpleString("sys.path.append('/home/allen/python')"); 
    PyObject *html2excelModule = PyImport_ImportModule("html2excel"); 
    if (!html2excelModule) 
    { 
     std::cerr << "Error: open python html2excel failed" << std::endl; 
     Py_Finalize(); 
     return -1; 
    } 
    ... 
} 

上述計劃告訴給了我這個錯誤

ImportError: No module named html2excel

html2excel.py坐落在/ home /艾倫/蟒蛇。從shell運行可以。

$python 
>>>import sys 
>>>sys.path.append('/home/allen/python') 
>>>import html2excel 

爲什麼我的JNI庫無法導入現有的html2excel模塊?先謝謝你!

+0

您應該檢查之前函數的返回碼 –

+0

以前函數調用成功,全部返回0. – allenchen

回答

0

該錯誤消息表明rlm_python:除非:: /usr/lib/python2.7/lib-dynload/_io.so:未定義的符號:_Py_ZeroStruct

libpython2.7.so應手動通過使用加載的在JNI實現中使用dlopen。

詳細解決方案給出https://github.com/FreeRADIUS/freeradius-server/pull/415

+0

您應該通過添加鏈接中的相關信息來改進您的答案。 – manuell

相關問題