【发布时间】:2014-02-23 12:49:08
【问题描述】:
我知道有jython解决方案,但是jython不能加载wtxl和rdxl;它只能加载有限的 pip 库。所以我想写JNI来做。
主要程序如下: 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: 没有名为 html2excel 的模块
html2excel.py 位于 /home/allen/python。从shell运行就可以了。
$python
>>>import sys
>>>sys.path.append('/home/allen/python')
>>>import html2excel
为什么我的 JNI 库无法导入现有的 html2excel 模块?提前谢谢!
【问题讨论】:
-
你应该检查之前调用的函数的返回码
-
前面的函数调用成功,都返回0。
标签: java python c++ java-native-interface