【问题标题】:Invoking Jython from Python (or Vice Versa)从 Python(或 Vice Versa)调用 Jython
【发布时间】:2012-03-15 20:10:28
【问题描述】:

我现在正在开发一个框架,其中一部分需要 Jython。我只是使用 MatPlotLib 添加了一些绘图,但没有意识到 MatPlotLib 与 Jython 不兼容。由于这两个部分非常独立,我可以在 Python 中运行大部分程序并将少量信息传递给 Jython 部分(反之亦然),我想知道是否有一种简单的方法可以做到这一点,而保持框架的模块化特性。想法?

【问题讨论】:

  • 我认为 execnet 可能不是一个糟糕的选择。想法?

标签: python jython


【解决方案1】:

我没有将execnet 用于任何严重的事情,但它似乎很有可能对你来说是一个不错的选择。 execnet 是一个 Python 库,用于跨版本、平台和网络障碍进行分布式执行。

入门并不难。这个简单的 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

输出:

3

相反方向的文档includes an example(连接到 Jython 解释器的 CPython 解释器)。

【讨论】:

【解决方案2】:

没有在 execnet 中使用 MatPlotLib ...

但是……

要快速试用 execnet(在 win32 平台上),您可以使用 PortablePython2.7.2.1

PortablePython 包含 MatPlotLib,易于安装(和删除)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    • 1970-01-01
    • 2013-09-05
    相关资源
    最近更新 更多