Invoking Jython from Python (or Vice Versa)

回眸只為那壹抹淺笑 提交于 2019-12-17 18:56:33

问题


I'm working on a framework right now, part of which requires Jython. I just added some plotting to it using MatPlotLib, without realizing that MatPlotLib is incompatible with Jython. Since these two parts are pretty isolated, and I would be fine running most of the program in Python and passing a small amount of information to the Jython part (or vice versa), I was wondering if there's a simple way to do this, while maintaining the modular nature of the framework. Ideas?


回答1:


I have not used execnet for anything serious, but it seems quite possible that it is a good choice for you. execnet is a Python library for distributed execution across version, platform, and network barriers.

It is not hard to get started. This simple Jython script (that invokes NumPy) worked for me without a hitch:

import execnet

gw = execnet.makegateway("popen//python=python")
channel = gw.remote_exec("""
    from numpy import *
    a = array([2,3,4])
    channel.send(a.size)
""")

for item in channel:
    print item

Output:

3

The documentation includes an example that goes in the opposite direction (a CPython interpreter connecting to a Jython interpreter).




回答2:


Didn't use MatPlotLib with execnet ...

But ...

For a quick tryout with execnet (on a win32 platform) you can use PortablePython2.7.2.1

PortablePython contains the MatPlotLib and is easy to install (and remove)



来源:https://stackoverflow.com/questions/9727398/invoking-jython-from-python-or-vice-versa

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!