python怎么封装供java调用,使用jython从Java调用python并传递参数

I want to call python from the java code and pass the parameters to function in python. I have encapsulated a function in python. But the thing is I have also imported third party library sklearn in the python program. When I call a test program and pass the value to python, I am able to run the code. But when I tried using third party library such as sklearn and import in the python code, I got following error.

ImportError: No module named sklearn

I initialized object for the class PythonInterpreter and then using the following command, I included the path for the sklearn

this.interpreter.exec("import sys");

this.interpreter.exec("sys.path.append(\"/usr/local/lib/python2.7/dist-packages/sklearn\")");

Can anyone tell how to fix this problem? How to include third party library in the jython code and run the program?

解决方案

As sklearn depends on native CPython extensions, it currently won't work with Jython. However, keep an eye on JyNI (www.jyni.org), which will vastly improve this issue, but is still in an early state. Until JyNI is sufficiently mature, you can use one of the following projects:

They work by embedding the CPython interpreter and don't integrate with Jython. Still, if you depend on things like scikit or numpy, these are currently the only workable approaches to use your Python-code from Java.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值