简体   繁体   English

从Python(或反之亦然)调用Jython

[英]Invoking Jython from Python (or Vice Versa)

I'm working on a framework right now, part of which requires Jython. 我正在研究一个框架,其中一部分需要Jython。 I just added some plotting to it using MatPlotLib, without realizing that MatPlotLib is incompatible with Jython. 我刚刚使用MatPlotLib添加了一些绘图,但没有意识到MatPlotLib与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. 由于这两个部分相当孤立,我可以很好地运行Python中的大部分程序并将少量信息传递给Jython部分(反之亦然),我想知道是否有一种简单的方法可以做到这一点,而保持框架的模块化特性。 Ideas? 想法?

I have not used execnet for anything serious, but it seems quite possible that it is a good choice for you. 我没有使用过execnet用于任何严肃的事情,但它似乎很可能对你来说是一个不错的选择。 execnet is a Python library for distributed execution across version, platform, and network barriers. execnet是一个Python库,用于跨版本,平台和网络障碍进行分布式执行。

It is not hard to get started. 开始并不难。 This simple Jython script (that invokes NumPy) worked for me without a hitch: 这个简单的Jython脚本(调用NumPy)对我来说毫无障碍:

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). 该文档包含一个相反方向的示例 (连接到Jython解释器的CPython解释器)。

Didn't use MatPlotLib with execnet ... 没有使用MatclotLib与execnet ...

But ... 但......

For a quick tryout with execnet (on a win32 platform) you can use PortablePython2.7.2.1 对于使用execnet的快速试用(在win32平台上),您可以使用PortablePython2.7.2.1

PortablePython contains the MatPlotLib and is easy to install (and remove) PortablePython包含MatPlotLib,易于安装(和删除)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM